Index: 3rdParty_sources/aspirin/org/apache/james/core/MailHeaders.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/apache/james/core/MailHeaders.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/apache/james/core/MailHeaders.java 17 Aug 2012 14:15:44 -0000 1.1 @@ -0,0 +1,148 @@ +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache", "Jakarta", "JAMES" and "Apache Software Foundation" + * must not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * Portions of this software are based upon public domain software + * originally written at the National Center for Supercomputing Applications, + * University of Illinois, Urbana-Champaign. + */ + +package org.apache.james.core; + +import javax.mail.MessagingException; +import javax.mail.internet.InternetHeaders; +import java.io.*; +import java.util.Enumeration; + +import org.apache.james.util.RFC2822Headers; + +/** + * This interface defines a container for mail headers. Each header must use + * MIME format:
name: value
. + * + * @author Federico Barbieri + */ +public class MailHeaders extends InternetHeaders implements Serializable, Cloneable { + + /** + * No argument constructor + * + * @throws MessagingException if the super class cannot be properly instantiated + */ + public MailHeaders() throws MessagingException { + super(); + } + + /** + * Constructor that takes an InputStream containing the contents + * of the set of mail headers. + * + * @param in the InputStream containing the header data + * + * @throws MessagingException if the super class cannot be properly instantiated + * based on the stream + */ + public MailHeaders(InputStream in) throws MessagingException { + super(in); + } + + /** + * Write the headers to an output stream + * + * @param writer the stream to which to write the headers + */ + public void writeTo(OutputStream out) { + PrintStream pout; + if (out instanceof PrintStream) { + pout = (PrintStream)out; + } else { + pout = new PrintStream(out); + } + for (Enumeration e = super.getAllHeaderLines(); e.hasMoreElements(); ) { + pout.print((String) e.nextElement()); + pout.print("\r\n"); + } + // Print trailing CRLF + pout.print("\r\n"); + } + + /** + * Generate a representation of the headers as a series of bytes. + * + * @return the byte array containing the headers + */ + public byte[] toByteArray() { + ByteArrayOutputStream headersBytes = new ByteArrayOutputStream(); + writeTo(headersBytes); + return headersBytes.toByteArray(); + } + + /** + * Check if a particular header is present. + * + * @return true if the header is present, false otherwise + */ + public boolean isSet(String name) { + String[] value = super.getHeader(name); + return (value != null && value.length != 0); + } + + /** + * Check if all REQUIRED headers fields as specified in RFC 822 + * are present. + * + * @return true if the headers are present, false otherwise + */ + public boolean isValid() { + return (isSet(RFC2822Headers.DATE) && isSet(RFC2822Headers.TO) && isSet(RFC2822Headers.FROM)); + } +} Index: 3rdParty_sources/aspirin/org/apache/james/core/MailImpl.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/apache/james/core/MailImpl.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/apache/james/core/MailImpl.java 17 Aug 2012 14:15:44 -0000 1.1 @@ -0,0 +1,659 @@ +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache", "Jakarta", "JAMES" and "Apache Software Foundation" + * must not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * Portions of this software are based upon public domain software + * originally written at the National Center for Supercomputing Applications, + * University of Illinois, Urbana-Champaign. + */ + +package org.apache.james.core; + +//import org.apache.avalon.framework.activity.Disposable; + +import org.apache.james.util.RFC2822Headers; +import org.apache.mailet.Mail; +import org.apache.mailet.MailAddress; + +import javax.mail.Address; +import javax.mail.Message; +import javax.mail.MessagingException; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; +import javax.mail.internet.ParseException; +import java.io.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.Iterator; + +/** + * Wraps a MimeMessage adding routing information (from SMTP) and some simple + * API enhancements. + * + * @author Federico Barbieri + * @author Serge Knystautas + * @author Stuart Roebuck + * @version 0.9 + */ +public class MailImpl implements Mail { + /** + * We hardcode the serialVersionUID so that from James 1.2 on, MailImpl will + * be deserializable (so your mail doesn't get lost) + */ + public static final long serialVersionUID = -4289663364703986260L; + + /** + * The error message, if any, associated with this mail. + */ + private String errorMessage; + + /** + * The state of this mail, which determines how it is processed. + */ + private String state; + + /** + * The MimeMessage that holds the mail data. + */ + private MimeMessage message; + + /** + * The sender of this mail. + */ + private MailAddress sender; + + /** + * The collection of recipients to whom this mail was sent. + */ + private Collection recipients; + + /** + * The identifier for this mail message + */ + private String name; + + /** + * The remote host from which this mail was sent. + */ + private String remoteHost = "localhost"; + + /** + * The remote address from which this mail was sent. + */ + private String remoteAddr = "127.0.0.1"; + + /** + * The last time this message was updated. + */ + private Date lastUpdated = new Date(); + + /** + * A constructor that creates a new, uninitialized MailImpl + */ + public MailImpl() { + setState(Mail.DEFAULT); + } + + /** + * A constructor that creates a MailImpl with the specified name, sender, + * and recipients. + * + * @param name + * the name of the MailImpl + * @param sender + * the sender for this MailImpl + * @param recipients + * the collection of recipients of this MailImpl + */ + public MailImpl(String name, MailAddress sender, Collection recipients) { + this(); + this.name = name; + this.sender = sender; + this.recipients = null; + + // Copy the recipient list + if (recipients != null) { + Iterator theIterator = recipients.iterator(); + this.recipients = new ArrayList(); + while (theIterator.hasNext()) { + this.recipients.add(theIterator.next()); + } + } + } + + /** + * A constructor that creates a MailImpl with the specified name, sender, + * recipients, and message data. + * + * @param name + * the name of the MailImpl + * @param sender + * the sender for this MailImpl + * @param recipients + * the collection of recipients of this MailImpl + * @param messageIn + * a stream containing the message source + */ + public MailImpl(String name, MailAddress sender, Collection recipients, + InputStream messageIn) throws MessagingException { + this(name, sender, recipients); + MimeMessageSource source = new MimeMessageInputStreamSource(name, + messageIn); + MimeMessageWrapper wrapper = new MimeMessageWrapper(source); + this.setMessage(wrapper); + } + + /** + * A constructor that creates a MailImpl with the specified name, sender, + * recipients, and MimeMessage. + * + * @param name + * the name of the MailImpl + * @param sender + * the sender for this MailImpl + * @param recipients + * the collection of recipients of this MailImpl + * @param message + * the MimeMessage associated with this MailImpl + */ + public MailImpl(String name, MailAddress sender, Collection recipients, + MimeMessage message) { + this(name, sender, recipients); + this.setMessage(message); + } + + /** + * A constructor which will attempt to obtain sender and recipients from the + * headers of the MimeMessage supplied. + * + * @param message - + * a MimeMessage from which to construct a Mail + */ + public MailImpl(MimeMessage message) throws MessagingException { + this(); + Address[] addresses; + addresses = message.getFrom(); + MailAddress sender = new MailAddress(new InternetAddress(addresses[0] + .toString())); + Collection recipients = new ArrayList(); + addresses = message.getRecipients(MimeMessage.RecipientType.TO); + if (addresses != null) { + for (int i = 0; i < addresses.length; i++) { + recipients.add(new MailAddress(new InternetAddress(addresses[i] + .toString()))); + } + } + + // Added by masukomi + // prior to this it would barf if it was lacking a To even if it had a CC or BCC + addresses = message.getRecipients(MimeMessage.RecipientType.CC); + if (addresses != null) { + for (int i = 0; i < addresses.length; i++) { + recipients.add(new MailAddress(new InternetAddress(addresses[i] + .toString()))); + } + } + addresses = message.getRecipients(MimeMessage.RecipientType.BCC); + if (addresses != null) { + for (int i = 0; i < addresses.length; i++) { + recipients.add(new MailAddress(new InternetAddress(addresses[i] + .toString()))); + } + } + // end added by masukomi + this.name = message.toString(); + this.sender = sender; + this.recipients = recipients; + this.setMessage(message); + } + + /** + * Duplicate the MailImpl. + * + * @return a MailImpl that is a duplicate of this one + */ + public Mail duplicate() { + return duplicate(name); + } + + /** + * Duplicate the MailImpl, replacing the mail name with the one passed in as + * an argument. + * + * @param newName + * the name for the duplicated mail + * + * @return a MailImpl that is a duplicate of this one with a different name + */ + public Mail duplicate(String newName) { + try { + MailImpl newMail = new MailImpl(newName, sender, recipients, + getMessage()); + newMail.setRemoteHost(remoteHost); + newMail.setRemoteAddr(remoteAddr); + newMail.setLastUpdated(lastUpdated); + return newMail; + } catch (MessagingException me) { + // Ignored. Return null in the case of an error. + } + return (Mail) null; + } + + /** + * Get the error message associated with this MailImpl. + * + * @return the error message associated with this MailImpl + */ + public String getErrorMessage() { + return errorMessage; + } + + /** + * Get the MimeMessage associated with this MailImpl. + * + * @return the MimeMessage associated with this MailImpl + */ + public MimeMessage getMessage() throws MessagingException { + return message; + } + + /** + * Set the name of this MailImpl. + * + * @param name + * the name of this MailImpl + */ + public void setName(String name) { + this.name = name; + } + + /** + * Get the name of this MailImpl. + * + * @return the name of this MailImpl + */ + public String getName() { + return name; + } + + /** + * Get the recipients of this MailImpl. + * + * @return the recipients of this MailImpl + */ + public Collection getRecipients() { + return recipients; + } + + /** + * Get the sender of this MailImpl. + * + * @return the sender of this MailImpl + */ + public MailAddress getSender() { + return sender; + } + + /** + * Get the state of this MailImpl. + * + * @return the state of this MailImpl + */ + public String getState() { + return state; + } + + /** + * Get the remote host associated with this MailImpl. + * + * @return the remote host associated with this MailImpl + */ + public String getRemoteHost() { + return remoteHost; + } + + /** + * Get the remote address associated with this MailImpl. + * + * @return the remote address associated with this MailImpl + */ + public String getRemoteAddr() { + return remoteAddr; + } + + /** + * Get the last updated time for this MailImpl. + * + * @return the last updated time for this MailImpl + */ + public Date getLastUpdated() { + return lastUpdated; + } + + /** + *

+ * Return the size of the message including its headers. + * MimeMessage.getSize() method only returns the size of the message body. + *

+ * + *

+ * Note: this size is not guaranteed to be accurate - see Sun's + * documentation of MimeMessage.getSize(). + *

+ * + * @return approximate size of full message including headers. + * + * @throws MessagingException + * if a problem occurs while computing the message size + */ + public long getMessageSize() throws MessagingException { + //If we have a MimeMessageWrapper, then we can ask it for just the + // message size and skip calculating it + if (message instanceof MimeMessageWrapper) { + MimeMessageWrapper wrapper = (MimeMessageWrapper) message; + return wrapper.getMessageSize(); + } + //SK: Should probably eventually store this as a locally + // maintained value (so we don't have to load and reparse + // messages each time). + long size = message.getSize(); + Enumeration e = message.getAllHeaderLines(); + while (e.hasMoreElements()) { + size += ((String) e.nextElement()).length(); + } + return size; + } + + /** + * Set the error message associated with this MailImpl. + * + * @param msg + * the new error message associated with this MailImpl + */ + public void setErrorMessage(String msg) { + this.errorMessage = msg; + } + + /** + * Set the MimeMessage associated with this MailImpl. + * + * @param message + * the new MimeMessage associated with this MailImpl + */ + public void setMessage(MimeMessage message) { + this.message = message; + } + + /** + * Set the recipients for this MailImpl. + * + * @param recipients + * the recipients for this MailImpl + */ + public void setRecipients(Collection recipients) { + this.recipients = recipients; + } + + /** + * Set the sender of this MailImpl. + * + * @param sender + * the sender of this MailImpl + */ + public void setSender(MailAddress sender) { + this.sender = sender; + } + + /** + * Set the state of this MailImpl. + * + * @param state + * the state of this MailImpl + */ + public void setState(String state) { + this.state = state; + } + + /** + * Set the remote address associated with this MailImpl. + * + * @param remoteHost + * the new remote host associated with this MailImpl + */ + public void setRemoteHost(String remoteHost) { + this.remoteHost = remoteHost; + } + + /** + * Set the remote address associated with this MailImpl. + * + * @param remoteAddr + * the new remote address associated with this MailImpl + */ + public void setRemoteAddr(String remoteAddr) { + this.remoteAddr = remoteAddr; + } + + /** + * Set the date this mail was last updated. + * + * @param lastUpdated + * the date the mail was last updated + */ + public void setLastUpdated(Date lastUpdated) { + // Make a defensive copy to ensure that the date + // doesn't get changed external to the class + if (lastUpdated != null) { + lastUpdated = new Date(lastUpdated.getTime()); + } + this.lastUpdated = lastUpdated; + } + + /** + * Writes the message out to an OutputStream. + * + * @param out + * the OutputStream to which to write the content + * + * @throws MessagingException + * if the MimeMessage is not set for this MailImpl + * @throws IOException + * if an error occurs while reading or writing from the stream + */ + public void writeMessageTo(OutputStream out) throws IOException, + MessagingException { + if (message != null) { + message.writeTo(out); + } else { + throw new MessagingException("No message set for this MailImpl."); + } + } + + /** + * Generates a bounce mail that is a bounce of the original message. + * + * @param bounceText + * the text to be prepended to the message to describe the bounce + * condition + * + * @return the bounce mail + * + * @throws MessagingException + * if the bounce mail could not be created + */ + public Mail bounce(String bounceText) throws MessagingException { + //This sends a message to the james component that is a bounce of the + // sent message + MimeMessage original = getMessage(); + MimeMessage reply = (MimeMessage) original.reply(false); + reply.setSubject("Re: " + original.getSubject()); + Collection recipients = new HashSet(); + recipients.add(getSender()); + InternetAddress addr[] = { new InternetAddress(getSender().toString()) }; + reply.setRecipients(Message.RecipientType.TO, addr); + reply.setFrom(new InternetAddress(getRecipients().iterator().next() + .toString())); + reply.setText(bounceText); + reply.setHeader(RFC2822Headers.MESSAGE_ID, "replyTo-" + getName()); + return new MailImpl("replyTo-" + getName(), new MailAddress( + getRecipients().iterator().next().toString()), recipients, + reply); + } + + /** + * Writes the content of the message, up to a total number of lines, out to + * an OutputStream. + * + * @param out + * the OutputStream to which to write the content + * @param lines + * the number of lines to write to the stream + * + * @throws MessagingException + * if the MimeMessage is not set for this MailImpl + * @throws IOException + * if an error occurs while reading or writing from the stream + */ + public void writeContentTo(OutputStream out, int lines) throws IOException, + MessagingException { + String line; + BufferedReader br; + if (message != null) { + br = new BufferedReader(new InputStreamReader(message + .getInputStream())); + while (lines-- > 0) { + if ((line = br.readLine()) == null) { + break; + } + line += "\r\n"; + out.write(line.getBytes()); + } + } else { + throw new MessagingException("No message set for this MailImpl."); + } + } + + // Serializable Methods + // TODO: These need some work. Currently very tightly coupled to + // the internal representation. + /** + * Read the MailImpl from an ObjectInputStream. + * + * @param in + * the ObjectInputStream from which the object is read + * + * @throws IOException + * if an error occurs while reading from the stream + * @throws ClassNotFoundException ? + * @throws ClassCastException + * if the serialized objects are not of the appropriate type + */ + private void readObject(java.io.ObjectInputStream in) throws IOException, + ClassNotFoundException { + try { + Object obj = in.readObject(); + if (obj == null) { + sender = null; + } else if (obj instanceof String) { + sender = new MailAddress((String) obj); + } else if (obj instanceof MailAddress) { + sender = (MailAddress) obj; + } + } catch (ParseException pe) { + throw new IOException("Error parsing sender address: " + + pe.getMessage()); + } + recipients = (Collection) in.readObject(); + state = (String) in.readObject(); + errorMessage = (String) in.readObject(); + name = (String) in.readObject(); + remoteHost = (String) in.readObject(); + remoteAddr = (String) in.readObject(); + setLastUpdated((Date) in.readObject()); + } + + /** + * Write the MailImpl to an ObjectOutputStream. + * + * @param in + * the ObjectOutputStream to which the object is written + * + * @throws IOException + * if an error occurs while writing to the stream + */ + private void writeObject(java.io.ObjectOutputStream out) throws IOException { + lastUpdated = new Date(); + out.writeObject(sender); + out.writeObject(recipients); + out.writeObject(state); + out.writeObject(errorMessage); + out.writeObject(name); + out.writeObject(remoteHost); + out.writeObject(remoteAddr); + out.writeObject(lastUpdated); + } + + /** + * @see org.apache.avalon.framework.activity.Disposable#dispose() + */ + public void dispose() { + /* + * try { MimeMessage wrapper = getMessage(); if (wrapper instanceof + * Disposable) { ((Disposable)wrapper).dispose(); } } catch + * (MessagingException me) { // Ignored } + */ + } + +} \ No newline at end of file Index: 3rdParty_sources/aspirin/org/apache/james/core/MimeMessageInputStreamSource.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/apache/james/core/MimeMessageInputStreamSource.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/apache/james/core/MimeMessageInputStreamSource.java 17 Aug 2012 14:15:44 -0000 1.1 @@ -0,0 +1,198 @@ +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache", "Jakarta", "JAMES" and "Apache Software Foundation" + * must not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * Portions of this software are based upon public domain software + * originally written at the National Center for Supercomputing Applications, + * University of Illinois, Urbana-Champaign. + */ + +/* + * Copyright (C) The Apache Software Foundation. All rights reserved. + * + * This software is published under the terms of the Apache Software License + * version 1.1, a copy of which has been included with this distribution in + * the LICENSE file. + */ +package org.apache.james.core; + +import java.io.*; +import javax.mail.MessagingException; + +//import org.apache.avalon.framework.activity.Disposable; + +/** + * Takes an input stream and creates a repeatable input stream source + * for a MimeMessageWrapper. It does this by completely reading the + * input stream and saving that to a temporary file that should delete on exit, + * or when this object is GC'd. + * + * @see MimeMessageWrapper + * + * + * @author Serge Knystautas + */ +public class MimeMessageInputStreamSource + extends MimeMessageSource + { + + /** + * A temporary file used to hold the message stream + */ + File file = null; + + /** + * The full path of the temporary file + */ + String sourceId = null; + + /** + * Construct a new MimeMessageInputStreamSource from an + * InputStream that contains the bytes of a + * MimeMessage. + * + * @param key the prefix for the name of the temp file + * @param in the stream containing the MimeMessage + * + * @throws MessagingException if an error occurs while trying to store + * the stream + */ + public MimeMessageInputStreamSource(String key, InputStream in) + throws MessagingException { + //We want to immediately read this into a temporary file + //Create a temp file and channel the input stream into it + OutputStream fout = null; + try { + file = File.createTempFile(key, ".m64"); + fout = new BufferedOutputStream(new FileOutputStream(file)); + int b = -1; + while ((b = in.read()) != -1) { + fout.write(b); + } + fout.flush(); + + sourceId = file.getCanonicalPath(); + } catch (IOException ioe) { + throw new MessagingException("Unable to retrieve the data: " + ioe.getMessage(), ioe); + } finally { + try { + if (fout != null) { + fout.close(); + } + } catch (IOException ioe) { + // Ignored - logging unavailable to log this non-fatal error. + } + + try { + if (in != null) { + in.close(); + } + } catch (IOException ioe) { + // Ignored - logging unavailable to log this non-fatal error. + } + } + } + + /** + * Returns the unique identifier of this input stream source + * + * @return the unique identifier for this MimeMessageInputStreamSource + */ + public String getSourceId() { + return sourceId; + } + + /** + * Get an input stream to retrieve the data stored in the temporary file + * + * @return a BufferedInputStream containing the data + */ + public synchronized InputStream getInputStream() throws IOException { + return new BufferedInputStream(new FileInputStream(file)); + } + + /** + * Get the size of the temp file + * + * @return the size of the temp file + * + * @throws IOException if an error is encoutered while computing the size of the message + */ + public long getMessageSize() throws IOException { + return file.length(); + } + + /** + * @see org.apache.avalon.framework.activity.Disposable#dispose() + */ + public void dispose() { + /*try { + if (file != null && file.exists()) { + file.delete(); + } + } catch (Exception e) { + //ignore + } + file = null; + */ + } + + /** + *

Finalizer that closes and deletes the temp file. Very bad.

+ * We're leaving this in temporarily, while also establishing a more + * formal mechanism for cleanup through use of the dispose() method. + * + */ + public void finalize() { + dispose(); + } +} Index: 3rdParty_sources/aspirin/org/apache/james/core/MimeMessageSource.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/apache/james/core/MimeMessageSource.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/apache/james/core/MimeMessageSource.java 17 Aug 2012 14:15:44 -0000 1.1 @@ -0,0 +1,128 @@ +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache", "Jakarta", "JAMES" and "Apache Software Foundation" + * must not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * Portions of this software are based upon public domain software + * originally written at the National Center for Supercomputing Applications, + * University of Illinois, Urbana-Champaign. + */ + +/* + * Copyright (C) The Apache Software Foundation. All rights reserved. + * + * This software is published under the terms of the Apache Software License + * version 1.1, a copy of which has been included with this distribution in + * the LICENSE file. + */ +package org.apache.james.core; + +import java.io.IOException; +import java.io.InputStream; + +/** + * This defines a reusable datasource that can supply an input stream with + * MimeMessage data. This allows a MimeMessageWrapper or other classes to + * grab the underlying data. + * + * @see MimeMessageWrapper + */ +public abstract class MimeMessageSource { + /** + * Returns a unique String ID that represents the location from where + * this file is loaded. This will be used to identify where the data + * is, primarily to avoid situations where this data would get overwritten. + * + * @return the String ID + */ + public abstract String getSourceId(); + + /** + * Get an input stream to retrieve the data stored in the datasource + * + * @return a InputStream containing the data + * + * @throws IOException if an error occurs while generating the + * InputStream + */ + public abstract InputStream getInputStream() throws IOException; + + /** + * Return the size of all the data. + * Default implementation... others can override to do this much faster + * + * @return the size of the data represented by this source + * @throws IOException if an error is encountered while computing the message size + */ + public long getMessageSize() throws IOException { + int size = 0; + InputStream in = null; + try { + in = getInputStream(); + int read = 0; + byte[] data = new byte[1024]; + while ((read = in.read(data)) > 0) { + size += read; + } + } finally { + try { + if (in != null) { + in.close(); + } + } catch (IOException ioe) { + // Exception ignored because logging is + // unavailable + } + } + return size; + } + +} Index: 3rdParty_sources/aspirin/org/apache/james/core/MimeMessageWrapper.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/apache/james/core/MimeMessageWrapper.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/apache/james/core/MimeMessageWrapper.java 17 Aug 2012 14:15:44 -0000 1.1 @@ -0,0 +1,1092 @@ +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache", "Jakarta", "JAMES" and "Apache Software Foundation" + * must not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * Portions of this software are based upon public domain software + * originally written at the National Center for Supercomputing Applications, + * University of Illinois, Urbana-Champaign. + */ + +/* + * Copyright (C) The Apache Software Foundation. All rights reserved. + * + * This software is published under the terms of the Apache Software License + * version 1.1, a copy of which has been included with this distribution in + * the LICENSE file. + */ +package org.apache.james.core; + +import java.io.BufferedWriter; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.LineNumberReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.io.SequenceInputStream; +import java.io.UnsupportedEncodingException; +import java.text.ParseException; +import java.util.Date; +import java.util.Enumeration; + +import javax.activation.DataHandler; +import javax.mail.Address; +import javax.mail.Flags; +import javax.mail.Message; +import javax.mail.MessagingException; +import javax.mail.Multipart; +import javax.mail.Session; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.InternetHeaders; +import javax.mail.internet.MimeMessage; +import javax.mail.internet.MimeUtility; +import javax.mail.internet.NewsAddress; + +import org.apache.james.util.InternetPrintWriter; +import org.apache.james.util.RFC2822Headers; +import org.apache.james.util.RFC822DateFormat; + +//import org.apache.avalon.framework.activity.Disposable; +//import org.apache.avalon.excalibur.io.IOUtil; + +/** + * This object wraps a MimeMessage, only loading the underlying MimeMessage + * object when needed. Also tracks if changes were made to reduce + * unnecessary saves. + */ +public class MimeMessageWrapper + extends MimeMessage + { + + /** + * Can provide an input stream to the data + */ + MimeMessageSource source = null; + /** + * The Internet headers in memory + */ + MailHeaders headers = null; + /** + * The mime message in memory + */ + MimeMessage message = null; + /** + * Record whether a change was made to this message + */ + boolean modified = false; + /** + * How to format a mail date + */ + RFC822DateFormat mailDateFormat = new RFC822DateFormat(); + + /** + * A constructor that instantiates a MimeMessageWrapper based on + * a MimeMessageSource + * + * @param source the MimeMessageSource + */ + public MimeMessageWrapper(MimeMessageSource source) { + super(Session.getDefaultInstance(System.getProperties(), null)); + this.source = source; + } + + /** + * Returns the source ID of the MimeMessageSource that is supplying this + * with data. + * @see MimeMessageSource + */ + public String getSourceId() { + return source.getSourceId(); + } + + /** + * Load the message headers from the internal source. + * + * @throws MessagingException if an error is encountered while + * loading the headers + */ + private synchronized void loadHeaders() throws MessagingException { + if (headers != null) { + //Another thread has already loaded these headers + return; + } + try { + InputStream in = source.getInputStream(); + try { + headers = new MailHeaders(in); + } finally { + //IOUtil.shutdownStream(in); + in.close(); + } + } catch (IOException ioe) { + ioe.printStackTrace(); + throw new MessagingException("Unable to parse headers from stream: " + ioe.getMessage(), ioe); + } + } + + /** + * Load the complete MimeMessage from the internal source. + * + * @throws MessagingException if an error is encountered while + * loading the message + */ + private synchronized void loadMessage() throws MessagingException { + if (message != null) { + //Another thread has already loaded this message + return; + } + InputStream in = null; + try { + in = source.getInputStream(); + headers = new MailHeaders(in); + + ByteArrayInputStream headersIn + = new ByteArrayInputStream(headers.toByteArray()); + in = new SequenceInputStream(headersIn, in); + + message = new MimeMessage(session, in); + } catch (IOException ioe) { + ioe.printStackTrace(); + throw new MessagingException("Unable to parse stream: " + ioe.getMessage(), ioe); + } finally { + try { + //IOUtil.shutdownStream(in); + in.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + /** + * Internal implementation to get InternetAddress headers + */ + private Address[] getAddressHeader(String name) throws MessagingException { + String addr = getHeader(name, ","); + if (addr == null) { + return null; + } else { + return InternetAddress.parse(addr); + } + } + + + /** + * Internal implementation to find headers + */ + private String getHeaderName(Message.RecipientType recipienttype) throws MessagingException { + String s; + if (recipienttype == Message.RecipientType.TO) { + s = RFC2822Headers.TO; + } else if (recipienttype == Message.RecipientType.CC) { + s = RFC2822Headers.CC; + } else if (recipienttype == Message.RecipientType.BCC) { + s = RFC2822Headers.BCC; + } else if (recipienttype == RecipientType.NEWSGROUPS) { + s = "Newsgroups"; + } else { + throw new MessagingException("Invalid Recipient Type"); + } + return s; + } + + + /** + * Get whether the message has been modified. + * + * @return whether the message has been modified + */ + public boolean isModified() { + return modified; + } + + /** + * Rewritten for optimization purposes + */ + public void writeTo(OutputStream os) throws IOException, MessagingException { + if (message == null || !isModified()) { + // We do not want to instantiate the message... just read from source + // and write to this outputstream + InputStream in = source.getInputStream(); + try { + copyStream(in, os); + } finally { + //IOUtil.shutdownStream(in); + in.close(); + } + } else { + writeTo(os, os); + } + } + + /** + * Rewritten for optimization purposes + */ + public void writeTo(OutputStream os, String[] ignoreList) throws IOException, MessagingException { + writeTo(os, os, ignoreList); + } + + /** + * Write + */ + public void writeTo(OutputStream headerOs, OutputStream bodyOs) throws IOException, MessagingException { + writeTo(headerOs, bodyOs, new String[0]); + } + + public void writeTo(OutputStream headerOs, OutputStream bodyOs, String[] ignoreList) throws IOException, MessagingException { + if (message == null || !isModified()) { + //We do not want to instantiate the message... just read from source + // and write to this outputstream + + //First handle the headers + InputStream in = source.getInputStream(); + try { + InternetHeaders headers = new InternetHeaders(in); + PrintWriter pos = new InternetPrintWriter(new BufferedWriter(new OutputStreamWriter(headerOs), 512), true); + for (Enumeration e = headers.getNonMatchingHeaderLines(ignoreList); e.hasMoreElements(); ) { + String header = (String)e.nextElement(); + pos.println(header); + } + pos.println(); + pos.flush(); + copyStream(in, bodyOs); + } finally { + //IOUtil.shutdownStream(in); + in.close(); + } + } else { + writeTo(message, headerOs, bodyOs, ignoreList); + } + } + + /** + * Convenience method to take any MimeMessage and write the headers and body to two + * different output streams + */ + public static void writeTo(MimeMessage message, OutputStream headerOs, OutputStream bodyOs) throws IOException, MessagingException { + writeTo(message, headerOs, bodyOs, null); + } + + /** + * Convenience method to take any MimeMessage and write the headers and body to two + * different output streams, with an ignore list + */ + public static void writeTo(MimeMessage message, OutputStream headerOs, OutputStream bodyOs, String[] ignoreList) throws IOException, MessagingException { + if (message instanceof MimeMessageWrapper) { + MimeMessageWrapper wrapper = (MimeMessageWrapper)message; + wrapper.writeTo(headerOs, bodyOs, ignoreList); + } else { + if(message.getMessageID() == null) { + message.saveChanges(); + } + + //Write the headers (minus ignored ones) + Enumeration headers = message.getNonMatchingHeaderLines(ignoreList); + PrintWriter hos = new InternetPrintWriter(new BufferedWriter(new OutputStreamWriter(headerOs), 512), true); + while (headers.hasMoreElements()) { + hos.println((String)headers.nextElement()); + } + // Print header/data separator + hos.println(); + hos.flush(); + + InputStream bis = null; + OutputStream bos = null; + // Write the body to the output stream + + /* + try { + bis = message.getRawInputStream(); + bos = bodyOs; + } catch(javax.mail.MessagingException me) { + // we may get a "No content" exception + // if that happens, try it the hard way + + // Why, you ask? In JavaMail v1.3, when you initially + // create a message using MimeMessage APIs, there is no + // raw content available. getInputStream() works, but + // getRawInputStream() throws an exception. + + bos = MimeUtility.encode(bodyOs, message.getEncoding()); + bis = message.getInputStream(); + } + */ + + try { + // Get the message as a stream. This will encode + // objects as necessary, and we have some input from + // decoding an re-encoding the stream. I'd prefer the + // raw stream, but see + bos = MimeUtility.encode(bodyOs, message.getEncoding()); + bis = message.getInputStream(); + } catch(javax.activation.UnsupportedDataTypeException udte) { + /* If we get an UnsupportedDataTypeException try using + * the raw input stream as a "best attempt" at rendering + * a message. + * + * WARNING: JavaMail v1.3 getRawInputStream() returns + * INVALID (unchanged) content for a changed message. + * getInputStream() works properly, but in this case + * has failed due to a missing DataHandler. + * + * MimeMessage.getRawInputStream() may throw a "no + * content" MessagingException. In JavaMail v1.3, when + * you initially create a message using MimeMessage + * APIs, there is no raw content available. + * getInputStream() works, but getRawInputStream() + * throws an exception. If we catch that exception, + * throw the UDTE. It should mean that someone has + * locally constructed a message part for which JavaMail + * doesn't have a DataHandler. + */ + + try { + bis = message.getRawInputStream(); + bos = bodyOs; + } catch(javax.mail.MessagingException _) { + throw udte; + } + } + catch(javax.mail.MessagingException me) { + /* This could be another kind of MessagingException + * thrown by MimeMessage.getInputStream(), such as a + * javax.mail.internet.ParseException. + * + * The ParseException is precisely one of the reasons + * why the getRawInputStream() method exists, so that we + * can continue to stream the content, even if we cannot + * handle it. Again, if we get an exception, we throw + * the one that caused us to call getRawInputStream(). + */ + try { + bis = message.getRawInputStream(); + bos = bodyOs; + } catch(javax.mail.MessagingException _) { + throw me; + } + } + + try { + copyStream(bis, bos); + } + finally { + //IOUtil.shutdownStream(bis); + bis.close(); + } + } + } + + /** + * Various reader methods + */ + public Address[] getFrom() throws MessagingException { + if (headers == null) { + loadHeaders(); + } + Address from[] = getAddressHeader(RFC2822Headers.FROM); + if(from == null) { + from = getAddressHeader(RFC2822Headers.SENDER); + } + return from; + } + + public Address[] getRecipients(Message.RecipientType type) throws MessagingException { + if (headers == null) { + loadHeaders(); + } + if (type == RecipientType.NEWSGROUPS) { + String s = headers.getHeader("Newsgroups", ","); + if(s == null) { + return null; + } else { + return NewsAddress.parse(s); + } + } else { + return getAddressHeader(getHeaderName(type)); + } + } + + public Address[] getAllRecipients() throws MessagingException { + if (headers == null) { + loadHeaders(); + } + Address toAddresses[] = getRecipients(RecipientType.TO); + Address ccAddresses[] = getRecipients(RecipientType.CC); + Address bccAddresses[] = getRecipients(RecipientType.BCC); + Address newsAddresses[] = getRecipients(RecipientType.NEWSGROUPS); + if(ccAddresses == null && bccAddresses == null && newsAddresses == null) { + return toAddresses; + } + int i = (toAddresses == null ? 0 : toAddresses.length) + + (ccAddresses == null ? 0 : ccAddresses.length) + + (bccAddresses == null ? 0 : bccAddresses.length) + + (newsAddresses == null ? 0 : newsAddresses.length); + Address allAddresses[] = new Address[i]; + int j = 0; + if (toAddresses != null) { + System.arraycopy(toAddresses, 0, allAddresses, j, toAddresses.length); + j += toAddresses.length; + } + if(ccAddresses != null) { + System.arraycopy(ccAddresses, 0, allAddresses, j, ccAddresses.length); + j += ccAddresses.length; + } + if(bccAddresses != null) { + System.arraycopy(bccAddresses, 0, allAddresses, j, bccAddresses.length); + j += bccAddresses.length; + } + if(newsAddresses != null) { + System.arraycopy(newsAddresses, 0, allAddresses, j, newsAddresses.length); + j += newsAddresses.length; + } + return allAddresses; + } + + public Address[] getReplyTo() throws MessagingException { + if (headers == null) { + loadHeaders(); + } + Address replyTo[] = getAddressHeader(RFC2822Headers.REPLY_TO); + if(replyTo == null) { + replyTo = getFrom(); + } + return replyTo; + } + + public String getSubject() throws MessagingException { + if (headers == null) { + loadHeaders(); + } + String subject = getHeader(RFC2822Headers.SUBJECT, null); + if (subject == null) { + return null; + } + try { + return MimeUtility.decodeText(subject); + } catch(UnsupportedEncodingException _ex) { + return subject; + } + } + + public Date getSentDate() throws MessagingException { + if (headers == null) { + loadHeaders(); + } + String header = getHeader(RFC2822Headers.DATE, null); + if(header != null) { + try { + return mailDateFormat.parse(header); + } catch(ParseException _ex) { + return null; + } + } else { + return null; + } + } + + /** + * We do not attempt to define the received date, although in theory this is the last + * most date in the Received: headers. For now we return null, which means we are + * not implementing it. + */ + public Date getReceivedDate() throws MessagingException { + if (headers == null) { + loadHeaders(); + } + return null; + } + + /** + * This is the MimeMessage implementation - this should return ONLY the + * body, not the entire message (should not count headers). Will have + * to parse the message. + */ + public int getSize() throws MessagingException { + if (message == null) { + loadMessage(); + } + return message.getSize(); + } + + /** + * Corrects JavaMail 1.1 version which always returns -1. + * Only corrected for content less than 5000 bytes, + * to avoid memory hogging. + */ + public int getLineCount() throws MessagingException { + InputStream in=null; + try{ + in = getContentStream(); + }catch(Exception e){ + return -1; + } + if (in == null) { + return -1; + } + //Wrap input stream in LineNumberReader + //Not sure what encoding to use really... + try { + LineNumberReader counter = new LineNumberReader(new InputStreamReader(in, getEncoding())); + //Read through all the data + char[] block = new char[4096]; + while (counter.read(block) > -1) { + //Just keep reading + } + return counter.getLineNumber(); + } catch (IOException ioe) { + ioe.printStackTrace(); + return -1; + } finally { + try { + //IOUtil.shutdownStream(in); + in.close(); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + } + + /** + * Returns size of message, ie headers and content. Current implementation + * actually returns number of characters in headers plus number of bytes + * in the internal content byte array. + */ + public long getMessageSize() throws MessagingException { + try { + return source.getMessageSize(); + } catch (IOException ioe) { + throw new MessagingException("Error retrieving message size", ioe); + } + } + + public String getContentType() throws MessagingException { + if (headers == null) { + loadHeaders(); + } + String value = getHeader(RFC2822Headers.CONTENT_TYPE, null); + if (value == null) { + return "text/plain"; + } else { + return value; + } + } + + public boolean isMimeType(String mimeType) throws MessagingException { + if (message == null) { + loadMessage(); + } + return message.isMimeType(mimeType); + } + + public String getDisposition() throws MessagingException { + if (message == null) { + loadMessage(); + } + return message.getDisposition(); + } + + public String getEncoding() throws MessagingException { + if (message == null) { + loadMessage(); + } + return message.getEncoding(); + } + + public String getContentID() throws MessagingException { + if (headers == null) { + loadHeaders(); + } + return getHeader("Content-Id", null); + } + + public String getContentMD5() throws MessagingException { + if (headers == null) { + loadHeaders(); + } + return getHeader("Content-MD5", null); + } + + public String getDescription() throws MessagingException { + if (message == null) { + loadMessage(); + } + return message.getDescription(); + } + + public String[] getContentLanguage() throws MessagingException { + if (message == null) { + loadMessage(); + } + return message.getContentLanguage(); + } + + public String getMessageID() throws MessagingException { + if (headers == null) { + loadHeaders(); + } + return getHeader(RFC2822Headers.MESSAGE_ID, null); + } + + public String getFileName() throws MessagingException { + if (message == null) { + loadMessage(); + } + return message.getFileName(); + } + + public InputStream getInputStream() throws IOException, MessagingException { + if (message == null) { + //This is incorrect... supposed to return a decoded inputstream of + // the message body + //return source.getInputStream(); + loadMessage(); + return message.getInputStream(); + } else { + return message.getInputStream(); + } + } + + public DataHandler getDataHandler() throws MessagingException { + if (message == null) { + loadMessage(); + } + return message.getDataHandler(); + } + + public Object getContent() throws IOException, MessagingException { + if (message == null) { + loadMessage(); + } + return message.getContent(); + } + + public String[] getHeader(String name) throws MessagingException { + if (headers == null) { + loadHeaders(); + } + return headers.getHeader(name); + } + + public String getHeader(String name, String delimiter) throws MessagingException { + if (headers == null) { + loadHeaders(); + } + return headers.getHeader(name, delimiter); + } + + public Enumeration getAllHeaders() throws MessagingException { + if (headers == null) { + loadHeaders(); + } + return headers.getAllHeaders(); + } + + public Enumeration getMatchingHeaders(String[] names) throws MessagingException { + if (headers == null) { + loadHeaders(); + } + return headers.getMatchingHeaders(names); + } + + public Enumeration getNonMatchingHeaders(String[] names) throws MessagingException { + if (headers == null) { + loadHeaders(); + } + return headers.getNonMatchingHeaders(names); + } + + public Enumeration getAllHeaderLines() throws MessagingException { + if (headers == null) { + loadHeaders(); + } + return headers.getAllHeaderLines(); + } + + public Enumeration getMatchingHeaderLines(String[] names) throws MessagingException { + if (headers == null) { + loadHeaders(); + } + return headers.getMatchingHeaderLines(names); + } + + public Enumeration getNonMatchingHeaderLines(String[] names) throws MessagingException { + if (headers == null) { + loadHeaders(); + } + return headers.getNonMatchingHeaderLines(names); + } + + public Flags getFlags() throws MessagingException { + if (message == null) { + loadMessage(); + } + return message.getFlags(); + } + + public boolean isSet(Flags.Flag flag) throws MessagingException { + if (message == null) { + loadMessage(); + } + return message.isSet(flag); + } + + + /** + * Writes content only, ie not headers, to the specified OutputStream. + * + * @param outs the OutputStream to which the content is written + */ + public void writeContentTo(OutputStream outs) + throws java.io.IOException, MessagingException { + if (message == null) { + loadMessage(); + } + InputStream in = getContentStream(); + try { + copyStream(in, outs); + } finally { + //IOUtil.shutdownStream(in); + in.close(); + } + } + + /** + * Convenience method to copy streams + */ + private static void copyStream(InputStream in, OutputStream out) throws IOException { + // TODO: This is really a bad way to do this sort of thing. A shared buffer to + // allow simultaneous read/writes would be a substantial improvement + byte[] block = new byte[1024]; + int read = 0; + while ((read = in.read(block)) > -1) { + out.write(block, 0, read); + } + out.flush(); + } + + /* + * Various writer methods + */ + + public void setFrom(Address address) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + message.setFrom(address); + } + + public void setFrom() throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + message.setFrom(); + } + + public void addFrom(Address[] addresses) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + message.addFrom(addresses); + } + + public void setRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + message.setRecipients(type, addresses); + } + + public void addRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + message.addRecipients(type, addresses); + } + + public void setReplyTo(Address[] addresses) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + message.setReplyTo(addresses); + } + + public void setSubject(String subject) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + headers.setHeader(RFC2822Headers.SUBJECT, subject); + message.setSubject(subject); + } + + public void setSubject(String subject, String charset) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + // is this correct? + try { + headers.setHeader(RFC2822Headers.SUBJECT, new String(subject.getBytes(charset))); + } + catch (java.io.UnsupportedEncodingException _) { /* TODO */ } + message.setSubject(subject, charset); + } + + public void setSentDate(Date d) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + headers.setHeader(RFC2822Headers.DATE, mailDateFormat.format(d)); + message.setSentDate(d); + } + + public void setDisposition(String disposition) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + message.setDisposition(disposition); + } + + public void setContentID(String cid) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + message.setContentID(cid); + } + + public void setContentMD5(String md5) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + message.setContentMD5(md5); + } + + public void setDescription(String description) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + message.setDescription(description); + } + + public void setDescription(String description, String charset) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + message.setDescription(description, charset); + } + + public void setContentLanguage(String[] languages) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + message.setContentLanguage(languages); + } + + public void setFileName(String filename) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + message.setFileName(filename); + } + + public void setDataHandler(DataHandler dh) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + message.setDataHandler(dh); + } + + public void setContent(Object o, String type) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + message.setContent(o, type); + } + + public void setText(String text) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + message.setText(text); + } + + public void setText(String text, String charset) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + message.setText(text, charset); + } + + public void setContent(Multipart mp) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + message.setContent(mp); + } + + public Message reply(boolean replyToAll) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + return message.reply(replyToAll); + } + + public void setHeader(String name, String value) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + headers.setHeader(name, value); + message.setHeader(name, value); + } + + public void addHeader(String name, String value) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + headers.addHeader(name, value); + message.addHeader(name, value); + } + + public void removeHeader(String name) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + headers.removeHeader(name); + message.removeHeader(name); + } + + public void addHeaderLine(String line) throws MessagingException { + if (message == null) { + loadMessage(); + } + headers.addHeaderLine(line); + message.addHeaderLine(line); + } + + public void setFlags(Flags flag, boolean set) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + message.setFlags(flag, set); + } + + public void saveChanges() throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + message.saveChanges(); + } + + /* + * Since JavaMail 1.2 + */ + public InputStream getRawInputStream() throws MessagingException { + if (message == null) { + loadMessage(); + } + return message.getRawInputStream(); + } + + public void addRecipients(Message.RecipientType type, String addresses) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + message.addRecipients(type, addresses); + } + + public void setRecipients(Message.RecipientType type, String addresses) throws MessagingException { + if (message == null) { + loadMessage(); + } + modified = true; + message.setRecipients(type, addresses); + } + + /** + * @see org.apache.avalon.framework.activity.Disposable#dispose() + */ + /*public void dispose() { + if (source instanceof Disposable) { + ((Disposable)source).dispose(); + } + }*/ +} Index: 3rdParty_sources/aspirin/org/apache/james/util/Base64.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/apache/james/util/Base64.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/apache/james/util/Base64.java 17 Aug 2012 14:15:41 -0000 1.1 @@ -0,0 +1,118 @@ +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache", "Jakarta", "JAMES" and "Apache Software Foundation" + * must not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * Portions of this software are based upon public domain software + * originally written at the National Center for Supercomputing Applications, + * University of Illinois, Urbana-Champaign. + */ + +package org.apache.james.util; + +import javax.mail.internet.MimeUtility; +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStreamReader; + + +/** + * Simple Base64 string decoding function + * @author Jason Borden + * + * @version This is $Revision: 1.1 $ + */ + +public class Base64 { + + public static BufferedReader decode(String b64string) throws Exception { + return new BufferedReader( + new InputStreamReader( + MimeUtility.decode( + new ByteArrayInputStream( + b64string.getBytes()), "base64"))); + } + + public static String decodeAsString(String b64string) throws Exception { + if (b64string == null) { + return b64string; + } + String returnString = decode(b64string).readLine(); + if (returnString == null) { + return returnString; + } + return returnString.trim(); + } + + public static ByteArrayOutputStream encode(String plaintext) + throws Exception { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + byte[] in = plaintext.getBytes(); + ByteArrayOutputStream inStream = new ByteArrayOutputStream(); + inStream.write(in, 0, in.length); + // pad + if ((in.length % 3 ) == 1){ + inStream.write(0); + inStream.write(0); + } else if((in.length % 3 ) == 2){ + inStream.write(0); + } + inStream.writeTo( MimeUtility.encode(out, "base64") ); + return out; + } + + public static String encodeAsString(String plaintext) throws Exception { + return encode(plaintext).toString(); + } + + +} Index: 3rdParty_sources/aspirin/org/apache/james/util/InternetPrintWriter.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/apache/james/util/InternetPrintWriter.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/apache/james/util/InternetPrintWriter.java 17 Aug 2012 14:15:41 -0000 1.1 @@ -0,0 +1,243 @@ +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache", "Jakarta", "JAMES" and "Apache Software Foundation" + * must not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * Portions of this software are based upon public domain software + * originally written at the National Center for Supercomputing Applications, + * University of Illinois, Urbana-Champaign. + */ + +package org.apache.james.util; + +import java.io.OutputStream; +import java.io.PrintWriter; +import java.io.Writer; + +/** + * Writes to a wrapped Writer class, ensuring that all line separators are '\r\n', regardless + * of platform. + */ +public class InternetPrintWriter + extends PrintWriter { + + /** + * The line separator to use. + */ + private static String lineSeparator = "\r\n"; + + /** + * Whether the Writer autoflushes on line feeds + */ + private final boolean autoFlush; + + /** + * Constructor that takes a writer to wrap. + * + * @param out the wrapped Writer + */ + public InternetPrintWriter (Writer out) { + super (out); + autoFlush = false; + } + + /** + * Constructor that takes a writer to wrap. + * + * @param out the wrapped Writer + * @param autoFlush whether to flush after each print call + */ + public InternetPrintWriter (Writer out, boolean autoFlush) { + super (out, autoFlush); + this.autoFlush = autoFlush; + } + + /** + * Constructor that takes a stream to wrap. + * + * @param out the wrapped OutputStream + */ + public InternetPrintWriter (OutputStream out) { + super (out); + autoFlush = false; + } + + /** + * Constructor that takes a stream to wrap. + * + * @param out the wrapped OutputStream + * @param autoFlush whether to flush after each print call + */ + public InternetPrintWriter (OutputStream out, boolean autoFlush) { + super (out, autoFlush); + this.autoFlush = autoFlush; + } + + /** + * Print a line separator. + */ + public void println () { + synchronized (lock) { + write(lineSeparator); + if (autoFlush) { + flush(); + } + } + } + + /** + * Print a boolean followed by a line separator. + * + * @param x the boolean to print + */ + public void println(boolean x) { + synchronized (lock) { + print(x); + println(); + } + } + + /** + * Print a char followed by a line separator. + * + * @param x the char to print + */ + public void println(char x) { + synchronized (lock) { + print (x); + println (); + } + } + + /** + * Print a int followed by a line separator. + * + * @param x the int to print + */ + public void println (int x) { + synchronized (lock) { + print (x); + println (); + } + } + + /** + * Print a long followed by a line separator. + * + * @param x the long to print + */ + public void println (long x) { + synchronized (lock) { + print (x); + println (); + } + } + + /** + * Print a float followed by a line separator. + * + * @param x the float to print + */ + public void println (float x) { + synchronized (lock) { + print (x); + println (); + } + } + + /** + * Print a double followed by a line separator. + * + * @param x the double to print + */ + public void println (double x) { + synchronized (lock) { + print (x); + println (); + } + } + + /** + * Print a character array followed by a line separator. + * + * @param x the character array to print + */ + public void println (char[] x) { + synchronized (lock) { + print (x); + println (); + } + } + + /** + * Print a String followed by a line separator. + * + * @param x the String to print + */ + public void println (String x) { + synchronized (lock) { + print (x); + println (); + } + } + + /** + * Print an Object followed by a line separator. + * + * @param x the Object to print + */ + public void println (Object x) { + synchronized (lock) { + print (x); + println (); + } + } +} Index: 3rdParty_sources/aspirin/org/apache/james/util/RFC2822Headers.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/apache/james/util/RFC2822Headers.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/apache/james/util/RFC2822Headers.java 17 Aug 2012 14:15:41 -0000 1.1 @@ -0,0 +1,219 @@ +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache", "Jakarta", "JAMES" and "Apache Software Foundation" + * must not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * Portions of this software are based upon public domain software + * originally written at the National Center for Supercomputing Applications, + * University of Illinois, Urbana-Champaign. + */ + +package org.apache.james.util; + +/** + * This utility class provides the set of header names explicitly defined in RFC 2822 + * + * @author Peter M. Goldstein + */ +public class RFC2822Headers { + + // See Section 3.6.1 of RFC 2822 + + /** + * The name of the RFC 2822 header that stores the mail date. + */ + public final static String DATE = "Date"; + + // See Section 3.6.2 of RFC 2822 + + /** + * The name of the RFC 2822 header that stores the mail author(s). + */ + public final static String FROM = "From"; + + /** + * The name of the RFC 2822 header that stores the actual mail transmission agent, + * if this differs from the author of the message. + */ + public final static String SENDER = "Sender"; + + /** + * The name of the RFC 2822 header that stores the reply-to address. + */ + public final static String REPLY_TO = "Reply-To"; + + // See Section 3.6.3 of RFC 2822 + + /** + * The name of the RFC 2822 header that stores the primary mail recipients. + */ + public final static String TO = "To"; + + /** + * The name of the RFC 2822 header that stores the carbon copied mail recipients. + */ + public final static String CC = "Cc"; + + /** + * The name of the RFC 2822 header that stores the blind carbon copied mail recipients. + */ + public final static String BCC = "Bcc"; + + // See Section 3.6.4 of RFC 2822 + + /** + * The name of the RFC 2822 header that stores the message id. + */ + public final static String MESSAGE_ID = "Message-ID"; + + /** + * A common variation on the name of the RFC 2822 header that + * stores the message id. This is needed for certain filters and + * processing of incoming mail. + */ + public final static String MESSAGE_ID_VARIATION = "Message-Id"; + + /** + * The name of the RFC 2822 header that stores the message id of the message + * that to which this email is a reply. + */ + public final static String IN_REPLY_TO = "In-Reply-To"; + + /** + * The name of the RFC 2822 header that is used to identify the thread to + * which this message refers. + */ + public final static String REFERENCES = "References"; + + // See Section 3.6.5 of RFC 2822 + + /** + * The name of the RFC 2822 header that stores the subject. + */ + public final static String SUBJECT = "Subject"; + + /** + * The name of the RFC 2822 header that stores human-readable comments. + */ + public final static String COMMENTS = "Comments"; + + /** + * The name of the RFC 2822 header that stores human-readable keywords. + */ + public final static String KEYWORDS = "Keywords"; + + // See Section 3.6.6 of RFC 2822 + + /** + * The name of the RFC 2822 header that stores the date the message was resent. + */ + public final static String RESENT_DATE = "Resent-Date"; + + /** + * The name of the RFC 2822 header that stores the originator of the resent message. + */ + public final static String RESENT_FROM = "Resent-From"; + + /** + * The name of the RFC 2822 header that stores the transmission agent + * of the resent message. + */ + public final static String RESENT_SENDER = "Resent-Sender"; + + /** + * The name of the RFC 2822 header that stores the recipients + * of the resent message. + */ + public final static String RESENT_TO = "Resent-To"; + + /** + * The name of the RFC 2822 header that stores the carbon copied recipients + * of the resent message. + */ + public final static String RESENT_CC = "Resent-Cc"; + + /** + * The name of the RFC 2822 header that stores the blind carbon copied recipients + * of the resent message. + */ + public final static String RESENT_BCC = "Resent-Bcc"; + + /** + * The name of the RFC 2822 header that stores the message id + * of the resent message. + */ + public final static String RESENT_MESSAGE_ID = "Resent-Message-ID"; + + // See Section 3.6.7 of RFC 2822 + + /** + * The name of the RFC 2822 headers that store the tracing data for the return path. + */ + public final static String RETURN_PATH = "Return-Path"; + + /** + * The name of the RFC 2822 headers that store additional tracing data. + */ + public final static String RECEIVED = "Received"; + + // MIME headers + + /** + * The name of the MIME header that stores the content type. + */ + public final static String CONTENT_TYPE = "Content-Type"; + + /** + * Private constructor to prevent instantiation + */ + private RFC2822Headers() {} + +} Index: 3rdParty_sources/aspirin/org/apache/james/util/RFC822Date.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/apache/james/util/RFC822Date.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/apache/james/util/RFC822Date.java 17 Aug 2012 14:15:41 -0000 1.1 @@ -0,0 +1,214 @@ +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache", "Jakarta", "JAMES" and "Apache Software Foundation" + * must not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * Portions of this software are based upon public domain software + * originally written at the National Center for Supercomputing Applications, + * University of Illinois, Urbana-Champaign. + */ + +package org.apache.james.util; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; +import java.util.TimeZone; + +/** + * A utility class to allow creation of RFC822 date strings from Dates + * and dates from RFC822 strings
+ * It provides for conversion between timezones, + * And easy manipulation of RFC822 dates
+ * example - current timestamp: String nowdate = new RFC822Date().toString()
+ * example - convert into java.util.Date: Date usedate = new RFC822Date("3 Oct 2001 08:32:44 -0000").getDate()
+ * example - convert to timezone: String yourdate = new RFC822Date("3 Oct 2001 08:32:44 -0000", "GMT+02:00").toString()
+ * example - convert to local timezone: String mydate = new RFC822Date("3 Oct 2001 08:32:44 -0000").toString()
+ * @author Danny Angus (danny)
+ * @author Peter M. Goldstein
+ * + * @deprecated Use java.util.Date in combination with org.apache.james.util.RFC822DateFormat. + */ +public class RFC822Date { + private static SimpleDateFormat df; + private static SimpleDateFormat dx; + private static SimpleDateFormat dy; + private static SimpleDateFormat dz; + private Date d; + private RFC822DateFormat rfc822Format = new RFC822DateFormat(); + + static { + df = new SimpleDateFormat("EE, d MMM yyyy HH:mm:ss", Locale.US); + dx = new SimpleDateFormat("EE, d MMM yyyy HH:mm:ss zzzzz", Locale.US); + dy = new SimpleDateFormat("EE d MMM yyyy HH:mm:ss zzzzz", Locale.US); + dz = new SimpleDateFormat("d MMM yyyy HH:mm:ss zzzzz", Locale.US); + } + + /** + * creates a current timestamp + * using this machines system timezone
+ * + */ + public RFC822Date(){ + d = new Date(); + } + + /** + * creates object using date supplied + * and this machines system timezone
+ * @param da java.util.Date, A date object + */ + public RFC822Date(Date da) { + d = da; + } + + /** + * creates object using date supplied + * and the timezone string supplied
+ * useTZ can be either an abbreviation such as "PST", + * a full name such as "America/Los_Angeles",
+ * or a custom ID such as "GMT-8:00".
+ * Note that this is dependant on java.util.TimeZone
+ * Note that the support of abbreviations is for + * JDK 1.1.x compatibility only and full names should be used.
+ * @param da java.util.Date, a date object + * @param useTZ java.lang.Sting, a timezone string such as "America/Los_Angeles" or "GMT+02:00" + */ + public RFC822Date(Date da, String useTZ){ + d = da; + } + + /** + * creates object from + * RFC822 date string supplied + * and the system default time zone
+ * In practice it converts RFC822 date string to the local timezone
+ * @param rfcdate java.lang.String - date in RFC822 format "3 Oct 2001 08:32:44 -0000" + */ + public RFC822Date(String rfcdate) { + setDate(rfcdate); + } + /** + * creates object from + * RFC822 date string supplied + * using the supplied time zone string
+ * @param rfcdate java.lang.String - date in RFC822 format + * @param useTZ java.lang.String - timezone string *doesn't support Z style or UT* + */ + public RFC822Date(String rfcdate, String useTZ) { + setDate(rfcdate); + setTimeZone(useTZ); + } + + public void setDate(Date da){ + d = da; + } + + /** + * The following styles of rfc date strings can be parsed
+ * Wed, 3 Oct 2001 06:42:27 GMT+02:10
+ * Wed 3 Oct 2001 06:42:27 PST
+ * 3 October 2001 06:42:27 +0100
+ * the military style timezones, ZM, ZA, etc cannot (yet)
+ * @param rfcdate java.lang.String - date in RFC822 format + */ + public void setDate(String rfcdate) { + try { + synchronized (dx) { + d= dx.parse(rfcdate); + } + } catch(ParseException e) { + try { + synchronized (dz) { + d= dz.parse(rfcdate); + } + } catch(ParseException f) { + try { + synchronized (dy) { + d = dy.parse(rfcdate); + } + } catch(ParseException g) { + d = new Date(); + } + } + + } + + } + + public void setTimeZone(TimeZone useTZ) { + rfc822Format.setTimeZone(useTZ); + } + + public void setTimeZone(String useTZ) { + setTimeZone(TimeZone.getTimeZone(useTZ)); + } + + + /** + * returns the java.util.Date object this RFC822Date represents. + * @return java.util.Date - the java.util.Date object this RFC822Date represents. + */ + public Date getDate() { + return d; + } + + /** + * returns the date as a string formated for RFC822 compliance + * ,accounting for timezone and daylight saving. + * @return java.lang.String - date as a string formated for RFC822 compliance + * + */ + public String toString() { + return rfc822Format.format(d); + } +} Index: 3rdParty_sources/aspirin/org/apache/james/util/RFC822DateFormat.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/apache/james/util/RFC822DateFormat.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/apache/james/util/RFC822DateFormat.java 17 Aug 2012 14:15:41 -0000 1.1 @@ -0,0 +1,102 @@ +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache", "Jakarta", "JAMES" and "Apache Software Foundation" + * must not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * Portions of this software are based upon public domain software + * originally written at the National Center for Supercomputing Applications, + * University of Illinois, Urbana-Champaign. + */ + +package org.apache.james.util; + +import java.util.Date; +import javax.mail.internet.MailDateFormat; + +/** + * A thread safe wrapper for the javax.mail.internet.MailDateFormat class. + * + * @author Serge Knystautas + * @author Peter M. Goldstein + */ +public class RFC822DateFormat extends SynchronizedDateFormat { + /** + * A static instance of the RFC822DateFormat, used by toString + */ + private static RFC822DateFormat instance; + + static { + instance = new RFC822DateFormat(); + } + + /** + * This static method allows us to format RFC822 dates without + * explicitly instantiating an RFC822DateFormat object. + * + * @return java.lang.String + * @param d Date + * + * @deprecated This method is not necessary and is preserved for API + * backwards compatibility. Users of this class should + * instantiate an instance and use it as they would any + * other DateFormat object. + */ + public static String toString(Date d) { + return instance.format(d); + } + + /** + * Constructor for RFC822DateFormat + */ + public RFC822DateFormat() { + super(new MailDateFormat()); + } +} Index: 3rdParty_sources/aspirin/org/apache/james/util/SimplifiedDateFormat.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/apache/james/util/SimplifiedDateFormat.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/apache/james/util/SimplifiedDateFormat.java 17 Aug 2012 14:15:41 -0000 1.1 @@ -0,0 +1,125 @@ +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache", "Jakarta", "JAMES" and "Apache Software Foundation" + * must not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * Portions of this software are based upon public domain software + * originally written at the National Center for Supercomputing Applications, + * University of Illinois, Urbana-Champaign. + */ + +package org.apache.james.util; + +import java.text.ParseException; +import java.util.Date; +import java.util.TimeZone; + +/** + *

This interface is designed to provide a simplified subset of the + * methods provided by the java.text.DateFormat class.

+ * + *

This interface is necessary because of the difficulty in writing + * thread safe classes that inherit from java.text.DateFormat. + * This difficulty leads us to approach the problem using composition + * rather than inheritance. In general classes that implement this + * interface will delegate these calls to an internal DateFormat object.

+ * + * @author Peter M. Goldstein + */ +public interface SimplifiedDateFormat { + + /** + * Formats a Date into a date/time string. + * @param date the time value to be formatted into a time string. + * @return the formatted time string. + */ + public String format(Date d); + + /** + * Parses text from the beginning of the given string to produce a date. + * The method may not use the entire text of the given string. + * + * @param source A String whose beginning should be parsed. + * @return A Date parsed from the string. + * @throws ParseException if the beginning of the specified string + * cannot be parsed. + */ + public Date parse(String source) throws ParseException; + + /** + * Sets the time zone of this SimplifiedDateFormat object. + * @param zone the given new time zone. + */ + public void setTimeZone(TimeZone zone); + + /** + * Gets the time zone. + * @return the time zone associated with this SimplifiedDateFormat. + */ + public TimeZone getTimeZone(); + + /** + * Specify whether or not date/time parsing is to be lenient. With + * lenient parsing, the parser may use heuristics to interpret inputs that + * do not precisely match this object's format. With strict parsing, + * inputs must match this object's format. + * @param lenient when true, parsing is lenient + * @see java.util.Calendar#setLenient + */ + public void setLenient(boolean lenient); + + /** + * Tell whether date/time parsing is to be lenient. + * @return whether this SimplifiedDateFormat is lenient. + */ + public boolean isLenient(); +} + Index: 3rdParty_sources/aspirin/org/apache/james/util/SynchronizedDateFormat.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/apache/james/util/SynchronizedDateFormat.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/apache/james/util/SynchronizedDateFormat.java 17 Aug 2012 14:15:41 -0000 1.1 @@ -0,0 +1,205 @@ +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache", "Jakarta", "JAMES" and "Apache Software Foundation" + * must not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * Portions of this software are based upon public domain software + * originally written at the National Center for Supercomputing Applications, + * University of Illinois, Urbana-Champaign. + */ + +package org.apache.james.util; + +import java.text.ParseException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; +import java.util.TimeZone; + +/** + * This class is designed to be a synchronized wrapper for a + * java.text.DateFormat subclass. In general, + * these subclasses (most notably the java.text.SimpleDateFormat + * classes are not thread safe, so we need to synchronize on the + * internal DateFormat for all delegated calls. + * + * @author Peter M. Goldstein + */ +public class SynchronizedDateFormat implements SimplifiedDateFormat { + private final DateFormat internalDateFormat; + + /** + * Public constructor that mimics that of SimpleDateFormat. See + * java.text.SimpleDateFormat for more details. + * + * @param pattern the pattern that defines this DateFormat + * @param locale the locale + */ + public SynchronizedDateFormat(String pattern, Locale locale) { + internalDateFormat = new SimpleDateFormat(pattern, locale); + } + + /** + *

Wrapper method to allow child classes to synchronize a preexisting + * DateFormat.

+ * + *

TODO: Investigate replacing this with a factory method.

+ * + * @param the DateFormat to synchronize + */ + protected SynchronizedDateFormat(DateFormat theDateFormat) { + internalDateFormat = theDateFormat; + } + + /** + * SimpleDateFormat will handle most of this for us, but we + * want to ensure thread safety, so we wrap the call in a + * synchronized block. + * + * @return java.lang.String + * @param d Date + */ + public String format(Date d) { + synchronized (internalDateFormat) { + return internalDateFormat.format(d); + } + } + + /** + * Parses text from the beginning of the given string to produce a date. + * The method may not use the entire text of the given string. + *

+ * This method is designed to be thread safe, so we wrap our delegated + * parse method in an appropriate synchronized block. + * + * @param source A String whose beginning should be parsed. + * @return A Date parsed from the string. + * @throws ParseException if the beginning of the specified string + * cannot be parsed. + */ + public Date parse(String source) throws ParseException { + synchronized (internalDateFormat) { + return internalDateFormat.parse(source); + } + } + + /** + * Sets the time zone of this SynchronizedDateFormat object. + * @param zone the given new time zone. + */ + public void setTimeZone(TimeZone zone) { + synchronized(internalDateFormat) { + internalDateFormat.setTimeZone(zone); + } + } + + /** + * Gets the time zone. + * @return the time zone associated with this SynchronizedDateFormat. + */ + public TimeZone getTimeZone() { + synchronized(internalDateFormat) { + return internalDateFormat.getTimeZone(); + } + } + + /** + * Specify whether or not date/time parsing is to be lenient. With + * lenient parsing, the parser may use heuristics to interpret inputs that + * do not precisely match this object's format. With strict parsing, + * inputs must match this object's format. + * @param lenient when true, parsing is lenient + * @see java.util.Calendar#setLenient + */ + public void setLenient(boolean lenient) + { + synchronized(internalDateFormat) { + internalDateFormat.setLenient(lenient); + } + } + + /** + * Tell whether date/time parsing is to be lenient. + * @return whether this SynchronizedDateFormat is lenient. + */ + public boolean isLenient() + { + synchronized(internalDateFormat) { + return internalDateFormat.isLenient(); + } + } + + /** + * Overrides hashCode + */ + public int hashCode() { + synchronized(internalDateFormat) { + return internalDateFormat.hashCode(); + } + } + + /** + * Overrides equals + */ + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + synchronized(internalDateFormat) { + return internalDateFormat.equals(obj); + } + } + +} Index: 3rdParty_sources/aspirin/org/apache/mailet/Mail.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/apache/mailet/Mail.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/apache/mailet/Mail.java 17 Aug 2012 14:15:49 -0000 1.1 @@ -0,0 +1,153 @@ +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache", "Jakarta", "JAMES" and "Apache Software Foundation" + * must not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * Portions of this software are based upon public domain software + * originally written at the National Center for Supercomputing Applications, + * University of Illinois, Urbana-Champaign. + */ + +package org.apache.mailet; + +import javax.mail.MessagingException; +import javax.mail.internet.MimeMessage; +import java.io.Serializable; +import java.util.Collection; + +/** + * Wrap a MimeMessage with routing information (from SMTP) such + * as SMTP specified recipients, sender, and ip address and hostname + * of sending server. It also contains its state which represents + * which processor in the mailet container it is currently running. + * Special processor names are "root" and "error". + * + * @author Federico Barbieri + * @author Serge Knystautas + * @version 0.9 + */ +public interface Mail extends Serializable, Cloneable { + String GHOST = "ghost"; + String DEFAULT = "root"; + String ERROR = "error"; + String TRANSPORT = "transport"; + + /** + * Returns the MimeMessage stored in this message + * + * @return the MimeMessage that this Mail object wraps + * @throws MessagingException - an error occured while loading this object + */ + MimeMessage getMessage() throws MessagingException; + + /** + * Returns a Collection of MailAddress objects that are recipients of this message + * + * @return a Collection of MailAddress objects that are recipients of this message + */ + Collection getRecipients(); + + /** + * The sender of the message, as specified by the MAIL FROM header, or internally defined + * + * @return a MailAddress of the sender of this message + */ + MailAddress getSender(); + + /** + * The current state of the message, such as GHOST, ERROR, or DEFAULT + * + * @return the state of this message + */ + String getState(); + + /** + * The remote hostname of the server that connected to send this message + * + * @return a String of the hostname of the server that connected to send this message + */ + String getRemoteHost(); + + /** + * The remote ip address of the server that connected to send this message + * + * @return a String of the ip address of the server that connected to send this message + */ + String getRemoteAddr(); + + /** + * The error message, if any, associated with this message. Not sure why this is needed. + * + * @return a String of a descriptive error message + */ + String getErrorMessage(); + + /** + * Sets the error message associated with this message. Not sure why this is needed. + * + * @param msg - a descriptive error message + */ + void setErrorMessage(String msg); + + /** + * Sets the MimeMessage associated with this message via the object. + * + * @param message - the new MimeMessage that this Mail object will wrap + */ + void setMessage(MimeMessage message); + + /** + * Sets the state of this message. + * + * @param state - the new state of this message + */ + void setState(String state); +} Index: 3rdParty_sources/aspirin/org/apache/mailet/MailAddress.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/apache/mailet/MailAddress.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/apache/mailet/MailAddress.java 17 Aug 2012 14:15:49 -0000 1.1 @@ -0,0 +1,442 @@ +/* + * Copyright (C) The Apache Software Foundation. All rights reserved. + * + * This software is published under the terms of the Apache Software License + * version 1.1, a copy of which has been included with this distribution in + * the LICENSE file. + */ +package org.apache.mailet; + +import java.util.Locale; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.ParseException; + +/** + * A representation of an email address. + *

This class encapsulates functionalities to access to different + * parts of an email address without dealing with its parsing.

+ * + *

A MailAddress is an address specified in the MAIL FROM and + * RCPT TO commands in SMTP sessions. These are either passed by + * an external server to the mailet-compliant SMTP server, or they + * are created programmatically by the mailet-compliant server to + * send to another (external) SMTP server. Mailets and matchers + * use the MailAddress for the purpose of evaluating the sender + * and recipient(s) of a message.

+ * + *

MailAddress parses an email address as defined in RFC 821 + * (SMTP) p. 30 and 31 where addresses are defined in BNF convention. + * As the mailet API does not support the aged "SMTP-relayed mail" + * addressing protocol, this leaves all addresses to be a , + * as per the spec. The MailAddress's "user" is the of + * the and "host" is the of the mailbox.

+ * + *

This class is a good way to validate email addresses as there are + * some valid addresses which would fail with a simpler approach + * to parsing address. It also removes parsing burden from + * mailets and matchers that might not realize the flexibility of an + * SMTP address. For instance, "serge@home"@lokitech.com is a valid + * SMTP address (the quoted text serge@home is the user and + * lokitech.com is the host). This means all current parsing to date + * is incorrect as we just find the first @ and use that to separate + * user from host.

+ * + *

This parses an address as per the BNF specification for + * from RFC 821 on page 30 and 31, section 4.1.2. COMMAND SYNTAX. + * http://www.freesoft.org/CIE/RFC/821/15.htm

+ * + * @version 1.0 + * @author Roberto Lo Giacco + * @author Serge Knystautas + * @author Gabriel Bucher + * @author Stuart Roebuck + */ +public class MailAddress implements java.io.Serializable { + //We hardcode the serialVersionUID so that from James 1.2 on, + // MailAddress will be deserializable (so your mail doesn't get lost) + public static final long serialVersionUID = 2779163542539434916L; + + private final static char[] SPECIAL = + {'<', '>', '(', ')', '[', ']', '\\', '.', ',', ';', ':', '@', '\"'}; + + private String user = null; + private String host = null; + //Used for parsing + private int pos = 0; + + /** + *

Construct a MailAddress parsing the provided String object.

+ * + *

The personal variable is left empty.

+ * + * @param address the email address compliant to the RFC822 format + * @throws ParseException if the parse failed + */ + public MailAddress(String address) throws ParseException { + address = address.trim(); + StringBuffer userSB = new StringBuffer(); + StringBuffer hostSB = new StringBuffer(); + //Begin parsing + // ::= "@" + + try { + //parse local-part + // ::= | + if (address.charAt(pos) == '\"') { + userSB.append(parseQuotedLocalPart(address)); + } else { + userSB.append(parseUnquotedLocalPart(address)); + } + if (userSB.toString().length() == 0) { + throw new ParseException("No local-part (user account) found at position " + (pos + 1)); + } + + //find @ + if (address.charAt(pos) != '@') { + throw new ParseException("Did not find @ between local-part and domain at position " + (pos + 1)); + } + pos++; + + //parse domain + // ::= | "." + // ::= | "#" | "[" "]" + while (true) { + if (address.charAt(pos) == '#') { + hostSB.append(parseNumber(address)); + } else if (address.charAt(pos) == '[') { + hostSB.append(parseDotNum(address)); + } else { + hostSB.append(parseDomainName(address)); + } + if (pos >= address.length()) { + break; + } + if (address.charAt(pos) == '.') { + hostSB.append('.'); + pos++; + continue; + } + break; + } + + if (hostSB.toString().length() == 0) { + throw new ParseException("No domain found at position " + (pos + 1)); + } + } catch (IndexOutOfBoundsException ioobe) { + throw new ParseException("Out of data at position " + (pos + 1)); + } + + user = userSB.toString(); + host = hostSB.toString(); + } + + /** + * Construct a MailAddress with the provided personal name and email + * address. + * + * @param user the username or account name on the mail server + * @param host the server that should accept messages for this user + * @throws ParseException if the parse failed + */ + public MailAddress(String newUser, String newHost) throws ParseException { + /* NEEDS TO BE REWORKED TO VALIDATE EACH CHAR */ + user = newUser; + host = newHost; + } + + /** + * Constructs a MailAddress from a JavaMail InternetAddress, using only the + * email address portion, discarding the personal name. + */ + public MailAddress(InternetAddress address) throws ParseException { + this(address.getAddress()); + } + + /** + * Return the host part. + * + * @return a String object representing the host part + * of this email address. If the host is of the dotNum form + * (e.g. [yyy.yyy.yyy.yyy]) then strip the braces first. + */ + public String getHost() { + if (!(host.startsWith("[") && host.endsWith("]"))) { + return host; + } else { + return host.substring(1, host.length() -1); + } + } + + /** + * Return the user part. + * + * @return a String object representing the user part + * of this email address. + * @throws AddressException if the parse failed + */ + public String getUser() { + return user; + } + + public String toString() { + StringBuffer addressBuffer = + new StringBuffer(128) + .append(user) + .append("@") + .append(host); + return addressBuffer.toString(); + } + + public InternetAddress toInternetAddress() { + try { + return new InternetAddress(toString()); + } catch (javax.mail.internet.AddressException ae) { + //impossible really + return null; + } + } + + public boolean equals(Object obj) { + if (obj == null) { + return false; + } else if (obj instanceof String) { + String theString = (String)obj; + return toString().equalsIgnoreCase(theString); + } else if (obj instanceof MailAddress) { + MailAddress addr = (MailAddress)obj; + return getUser().equalsIgnoreCase(addr.getUser()) && getHost().equalsIgnoreCase(addr.getHost()); + } + return false; + } + + /** + * Return a hashCode for this object which should be identical for addresses + * which are equivalent. This is implemented by obtaining the default + * hashcode of the String representation of the MailAddress. Without this + * explicit definition, the default hashCode will create different hashcodes + * for separate object instances. + * + * @return the hashcode. + */ + public int hashCode() { + return toString().toLowerCase(Locale.US).hashCode(); + } + + private String parseQuotedLocalPart(String address) throws ParseException { + StringBuffer resultSB = new StringBuffer(); + resultSB.append('\"'); + pos++; + // ::= """ """ + // ::= "\" | "\" | | + while (true) { + if (address.charAt(pos) == '\"') { + resultSB.append('\"'); + //end of quoted string... move forward + pos++; + break; + } + if (address.charAt(pos) == '\\') { + resultSB.append('\\'); + pos++; + // ::= any one of the 128 ASCII characters (no exceptions) + char x = address.charAt(pos); + if (x < 0 || x > 128) { + throw new ParseException("Invalid \\ syntaxed character at position " + (pos + 1)); + } + resultSB.append(x); + pos++; + } else { + // ::= any one of the 128 ASCII characters except , + //, quote ("), or backslash (\) + char q = address.charAt(pos); + if (q <= 0 || q == '\n' || q == '\r' || q == '\"' || q == '\\') { + throw new ParseException("Unquoted local-part (user account) must be one of the 128 ASCI characters exception , , quote (\"), or backslash (\\) at position " + (pos + 1)); + } + resultSB.append(q); + pos++; + } + } + return resultSB.toString(); + } + + private String parseUnquotedLocalPart(String address) throws ParseException { + StringBuffer resultSB = new StringBuffer(); + // ::= | "." + boolean lastCharDot = false; + while (true) { + // ::= | + // ::= | "\" + if (address.charAt(pos) == '\\') { + resultSB.append('\\'); + pos++; + // ::= any one of the 128 ASCII characters (no exceptions) + char x = address.charAt(pos); + if (x < 0 || x > 128) { + throw new ParseException("Invalid \\ syntaxed character at position " + (pos + 1)); + } + resultSB.append(x); + pos++; + lastCharDot = false; + } else if (address.charAt(pos) == '.') { + resultSB.append('.'); + pos++; + lastCharDot = true; + } else if (address.charAt(pos) == '@') { + //End of local-part + break; + } else { + // ::= any one of the 128 ASCII characters, but not any + // or + // ::= "<" | ">" | "(" | ")" | "[" | "]" | "\" | "." + // | "," | ";" | ":" | "@" """ | the control + // characters (ASCII codes 0 through 31 inclusive and + // 127) + // ::= the space character (ASCII code 32) + char c = address.charAt(pos); + if (c <= 31 || c == 127 || c == ' ') { + throw new ParseException("Invalid character in local-part (user account) at position " + (pos + 1)); + } + for (int i = 0; i < SPECIAL.length; i++) { + if (c == SPECIAL[i]) { + throw new ParseException("Invalid character in local-part (user account) at position " + (pos + 1)); + } + } + resultSB.append(c); + pos++; + lastCharDot = false; + } + } + if (lastCharDot) { + throw new ParseException("local-part (user account) ended with a \".\", which is invalid."); + } + return resultSB.toString(); + } + + private String parseNumber(String address) throws ParseException { + // ::= | + + StringBuffer resultSB = new StringBuffer(); + //We keep the position from the class level pos field + while (true) { + if (pos >= address.length()) { + break; + } + // ::= any one of the ten digits 0 through 9 + char d = address.charAt(pos); + if (d == '.') { + break; + } + if (d < '0' || d > '9') { + throw new ParseException("In domain, did not find a number in # address at position " + (pos + 1)); + } + resultSB.append(d); + pos++; + } + return resultSB.toString(); + } + + private String parseDotNum(String address) throws ParseException { + //throw away all irrelevant '\' they're not necessary for escaping of '.' or digits, and are illegal as part of the domain-literal + while(address.indexOf("\\")>-1){ + address= address.substring(0,address.indexOf("\\")) + address.substring(address.indexOf("\\")+1); + } + StringBuffer resultSB = new StringBuffer(); + //we were passed the string with pos pointing the the [ char. + // take the first char ([), put it in the result buffer and increment pos + resultSB.append(address.charAt(pos)); + pos++; + + // ::= "." "." "." + for (int octet = 0; octet < 4; octet++) { + // ::= one, two, or three digits representing a decimal + // integer value in the range 0 through 255 + // ::= any one of the ten digits 0 through 9 + StringBuffer snumSB = new StringBuffer(); + for (int digits = 0; digits < 3; digits++) { + char d = address.charAt(pos); + if (d == '.') { + break; + } + if (d == ']') { + break; + } + if (d < '0' || d > '9') { + throw new ParseException("Invalid number at position " + (pos + 1)); + } + snumSB.append(d); + pos++; + } + if (snumSB.toString().length() == 0) { + throw new ParseException("Number not found at position " + (pos + 1)); + } + try { + int snum = Integer.parseInt(snumSB.toString()); + if (snum > 255) { + throw new ParseException("Invalid number at position " + (pos + 1)); + } + } catch (NumberFormatException nfe) { + throw new ParseException("Invalid number at position " + (pos + 1)); + } + resultSB.append(snumSB.toString()); + if (address.charAt(pos) == ']') { + if (octet < 3) { + throw new ParseException("End of number reached too quickly at " + (pos + 1)); + } else { + break; + } + } + if (address.charAt(pos) == '.') { + resultSB.append('.'); + pos++; + } + } + if (address.charAt(pos) != ']') { + throw new ParseException("Did not find closing bracket \"]\" in domain at position " + (pos + 1)); + } + resultSB.append(']'); + pos++; + return resultSB.toString(); + } + + private String parseDomainName(String address) throws ParseException { + StringBuffer resultSB = new StringBuffer(); + // ::= + // ::= | + // ::= | + // ::= | | "-" + // ::= any one of the 52 alphabetic characters A through Z + // in upper case and a through z in lower case + // ::= any one of the ten digits 0 through 9 + + // basically, this is a series of letters, digits, and hyphens, + // but it can't start with a digit or hypthen + // and can't end with a hyphen + + // in practice though, we should relax this as domain names can start + // with digits as well as letters. So only check that doesn't start + // or end with hyphen. + while (true) { + if (pos >= address.length()) { + break; + } + char ch = address.charAt(pos); + if ((ch >= '0' && ch <= '9') || + (ch >= 'a' && ch <= 'z') || + (ch >= 'A' && ch <= 'Z') || + (ch == '-')) { + resultSB.append(ch); + pos++; + continue; + } + if (ch == '.') { + break; + } + throw new ParseException("Invalid character at " + pos); + } + String result = resultSB.toString(); + if (result.startsWith("-") || result.endsWith("-")) { + throw new ParseException("Domain name cannot begin or end with a hyphen \"-\" at position " + (pos + 1)); + } + return result; + } +} Index: 3rdParty_sources/aspirin/org/masukomi/aspirin/core/Bouncer.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/masukomi/aspirin/core/Bouncer.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/masukomi/aspirin/core/Bouncer.java 17 Aug 2012 14:15:38 -0000 1.1 @@ -0,0 +1,122 @@ +/* + * Created on Jan 5, 2004 + * + * Copyright (c) 2004 Katherine Rhodes (masukomi at masukomi dot org) + * + * 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. + */ +package org.masukomi.aspirin.core; +import java.io.IOException; +import java.util.Collection; +import java.util.Date; +import java.util.HashSet; + +import javax.mail.Address; +import javax.mail.MessagingException; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeBodyPart; +import javax.mail.internet.MimeMessage; +import javax.mail.internet.MimeMultipart; + +import org.apache.commons.logging.Log; +import org.apache.james.util.RFC2822Headers; +import org.apache.james.util.RFC822DateFormat; +import org.apache.mailet.Mail; +import org.apache.mailet.MailAddress; +/** + * DOCUMENT ME! + * + * @author Administrator To change the template for this generated type comment + * go to Window - Preferences - Java - Code Generation - Code and + * Comments + */ +public class Bouncer { + static private Log log = Configuration.getInstance().getLog(); + /** An RFC822 date formatter used to format dates in mail headers */ + private static RFC822DateFormat rfc822DateFormat = new RFC822DateFormat(); + /** + * This generates a response to the Return-Path address, or the address of + * the message's sender if the Return-Path is not available. Note that this + * is different than a mail-client's reply, which would use the Reply-To or + * From header. + * + * @param mail + * DOCUMENT ME! + * @param message + * DOCUMENT ME! + * @param bouncer + * DOCUMENT ME! + * + * @throws MessagingException + * DOCUMENT ME! + */ + static public void bounce(MailQue que, Mail mail, String message, MailAddress bouncer) + throws MessagingException { + if (bouncer != null) { + if (log.isDebugEnabled()){ + log.debug("bouncing message to postmaster"); + } + MimeMessage orig = mail.getMessage(); + //Create the reply message + MimeMessage reply = (MimeMessage) orig.reply(false); + //If there is a Return-Path header, + if (orig.getHeader(RFC2822Headers.RETURN_PATH) != null) { + //Return the message to that address, not to the Reply-To + // address + reply.setRecipient(MimeMessage.RecipientType.TO, + new InternetAddress(orig + .getHeader(RFC2822Headers.RETURN_PATH)[0])); + } + //Create the list of recipients in our MailAddress format + Collection recipients = new HashSet(); + Address[] addresses = reply.getAllRecipients(); + for (int i = 0; i < addresses.length; i++) { + recipients.add(new MailAddress((InternetAddress) addresses[i])); + } + //Change the sender... + reply.setFrom(bouncer.toInternetAddress()); + try { + //Create the message body + MimeMultipart multipart = new MimeMultipart(); + //Add message as the first mime body part + MimeBodyPart part = new MimeBodyPart(); + part.setContent(message, "text/plain"); + part.setHeader(RFC2822Headers.CONTENT_TYPE, "text/plain"); + multipart.addBodyPart(part); + //Add the original message as the second mime body part + part = new MimeBodyPart(); + part.setContent(orig.getContent(), orig.getContentType()); + part.setHeader(RFC2822Headers.CONTENT_TYPE, orig + .getContentType()); + multipart.addBodyPart(part); + reply.setHeader(RFC2822Headers.DATE, rfc822DateFormat + .format(new Date())); + reply.setContent(multipart); + reply.setHeader(RFC2822Headers.CONTENT_TYPE, multipart + .getContentType()); + } catch (IOException ioe) { + throw new MessagingException("Unable to create multipart body", + ioe); + } + //Send it off... + //sendMail( bouncer, recipients, reply ); + que.queMail(reply); + } + } +} \ No newline at end of file Index: 3rdParty_sources/aspirin/org/masukomi/aspirin/core/Configuration.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/masukomi/aspirin/core/Configuration.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/masukomi/aspirin/core/Configuration.java 17 Aug 2012 14:15:37 -0000 1.1 @@ -0,0 +1,576 @@ +/* + * Created on Jan 5, 2004 + * + * Copyright (c) 2004 Katherine Rhodes (masukomi at masukomi dot org) + * + * 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. + */ +package org.masukomi.aspirin.core; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import javax.mail.Transport; +import javax.mail.internet.ParseException; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.mailet.MailAddress; + + +/** + *

This class represents the configuration of Aspirin. You can configure this + * software two ways:

+ * + *
    + *
  1. Get the configuration instance and set parameters.
  2. + *
  3. Get the instance and initialize with a Properties object.
  4. + *
+ * + *

There is a way to change behavior of Aspirin dinamically. You can use + * JMX to change configuration parameters. In the parameters list we marked the + * parameters which are applied immediately. For more informations view + * {@link ConfigurationMBean}.

+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
NameDeprecated nameTypeDescription
aspirin.delivery.attempt.delayaspirinRetryIntervalIntegerThe delay of next attempt to delivery in milliseconds. Change by + * JMX applied immediately.
aspirin.delivery.attempt.countaspirinMaxAttemptsIntegerMaximal number of delivery attempts of an email. Change by JMX + * applied immediately.
aspirin.delivery.debugBooleanIf true, full SMTP communication will be logged. Change by JMX + * applied immediately.
aspirin.delivery.threads.active.maxaspirinDeliverThreadsIntegerMaximum number of active delivery threads in the pool. Change by + * JMX applied immediately.
aspirin.delivery.threads.idle.maxaspirinDeliverThreadsIntegerMaximum number of idle delivery threads in the pool (the deilvery + * threads over this limit will be shutdown). Change by JMX applied + * immediately.
aspirin.delivery.timeoutIntegerSocket and {@link Transport} timeout in milliseconds. Change by + * JMX applied immediately.
aspirin.encodingStringThe MIME encoding. Change by JMX applied immediately.
aspirin.hostnameaspirinHostnameStringThe hostname. Change by JMX applied immediately.
aspirin.logger.nameString + * The name of the logger. Change by JMX applied immediately. + *
+ * WARNING! Changing logger name cause replacing of logger. + *
aspirin.logger.prefixStringThe prefix of the logger. This will be put in the logs at the first + * position. Change by JMX applied immediately.
aspirin.postmaster.emailaspirinPostmasterStringThe email address of the postmaster. Change by JMX applied + * immediately.
+ * + * @author Kate Rhodes masukomi at masukomi dot org + * @version $Id: Configuration.java,v 1.1 2012/08/17 14:15:37 marcin Exp $ + */ +public class Configuration implements ConfigurationMBean { + + private static Configuration instance; + private int maxAttempts = 3; // aspirin.delivery.attempt.count + private long retryInterval = 300000; // aspirin.delivery.attempt.delay + private boolean debugCommunication = false; // aspirin.delivery.debug + private String hostname = "localhost"; // aspirin.delivery.hostname + private int deliveryThreads = 3; // aspirin.delivery.threads.active.max + private int idleDeliveryThreads = deliveryThreads; // aspirin.delivery.threads.idle.max + private int connectionTimeout = 30000; // in milliseconds, aspirin.delivery.timeout + private String encoding = "UTF-8"; // aspirin.encoding + private static String loggerName = "Aspirin"; // aspirin.logger.name + private static Log log = LogFactory.getLog(loggerName); // inherited from aspirin.logger.name + private String loggerPrefix = "Aspirin "; // aspirin.logger.prefix + protected MailAddress postmaster = null; // inherited from aspirin.postmaster.email + + private List listeners; + + static public Configuration getInstance() { + if (instance == null) { + instance = new Configuration(); + } + return instance; + } + + public void init(Properties props) { + String tempString = null; + + tempString = props.getProperty(PARAM_DELIVERY_ATTEMPT_DELAY); + if( tempString != null ) + { + retryInterval = Long.valueOf(tempString); + }else + { + // We need this to support backward compatibility + tempString = System.getProperty("aspirinRetryInterval"); + if( tempString != null ) + { + retryInterval = Long.valueOf(tempString); + }else + { + tempString = System.getProperty(PARAM_DELIVERY_ATTEMPT_DELAY); + if( tempString != null ) + { + retryInterval = Long.valueOf(tempString); + } + } + } + + tempString = props.getProperty(PARAM_DELIVERY_ATTEMPT_COUNT); + if( tempString != null ) + { + maxAttempts = Integer.valueOf(tempString); + }else + { + // We need this to support backward compatibility + tempString = System.getProperty("aspirinMaxAttempts"); + if( tempString != null ) + { + maxAttempts = Integer.valueOf(tempString); + }else + { + tempString = System.getProperty(PARAM_DELIVERY_ATTEMPT_COUNT); + if( tempString != null ) + { + maxAttempts = Integer.valueOf(tempString); + } + } + } + + tempString = props.getProperty(PARAM_DELIVERY_DEBUG); + if( tempString != null ) + debugCommunication = ("true".equalsIgnoreCase(tempString) ) ? true : false; + + tempString = props.getProperty(PARAM_DELIVERY_THREADS_ACTIVE_MAX); + if( tempString != null ) + { + deliveryThreads = Integer.valueOf(tempString); + }else + { + // We need this to support backward compatibility + tempString = System.getProperty("aspirinDeliverThreads"); + if( tempString != null ) + { + deliveryThreads = Integer.valueOf(tempString); + }else + { + tempString = System.getProperty(PARAM_DELIVERY_THREADS_ACTIVE_MAX); + if( tempString != null ) + { + deliveryThreads = Integer.valueOf(tempString); + } + } + } + + tempString = props.getProperty(PARAM_DELIVERY_THREADS_IDLE_MAX); + if( tempString != null ) + { + idleDeliveryThreads = Integer.valueOf(tempString); + }else + { + // We need this to support backward compatibility + tempString = System.getProperty("aspirinDeliverThreads"); + if( tempString != null ) + { + idleDeliveryThreads = Integer.valueOf(tempString); + }else + { + tempString = System.getProperty(PARAM_DELIVERY_THREADS_IDLE_MAX); + if( tempString != null ) + { + idleDeliveryThreads = Integer.valueOf(tempString); + } + } + } + + tempString = props.getProperty(PARAM_DELIVERY_TIMEOUT); + if( tempString != null ) + connectionTimeout = Integer.valueOf(tempString); + + tempString = props.getProperty(PARAM_POSTMASTER_EMAIL); + if( tempString != null ) + { + setPostmasterEmail(tempString); + }else + { + tempString = System.getProperty("aspirinPostmaster"); + if( tempString != null ) + { + setPostmasterEmail(tempString); + }else + { + tempString = System.getProperty(PARAM_POSTMASTER_EMAIL); + if( tempString != null ) + { + setPostmasterEmail(tempString); + } + } + } + + hostname = props.getProperty( + PARAM_HOSTNAME, + System.getProperty("aspirinHostname", + System.getProperty("mail.smtp.host", + System.getProperty(PARAM_HOSTNAME, hostname) + ) + ) + ); + + encoding = props.getProperty(PARAM_ENCODING, encoding); + String loggerConfigName = props.getProperty(PARAM_LOGGER_NAME); + if( loggerConfigName != null && !loggerConfigName.equals(loggerName) ) + log = LogFactory.getLog(loggerName); + loggerPrefix = props.getProperty(PARAM_LOGGER_PREFIX, loggerPrefix); + } + + /** + * + */ + private Configuration() { + init(new Properties()); + } + /** + * @return the number of milliseconds the system will wait before trying to + * resend an e-mail. This defaults to 5 minutes. A normail mail + * server would wait a few hours at least but Aspirin can't assume + * that an appilication will be open for a few hours. + * + * @deprecated Use getDeliveryAttemptDelay() instead. + */ + public long getRetryInterval() { + return getDeliveryAttemptDelay(); + } + /** + * @param retryInterval + * The retryInterval to set. + * + * @deprecated Use setDeliveryAttemptDelay() instead. + */ + public void setRetryInterval(long retryInterval) { + setDeliveryAttemptDelay((int)retryInterval); + } + /** + * @return the number of threads in the thread pool available for mail + * delivery. This defaults to three. + * + * @deprecated Use getDeliveryThreadsActiveMax() instead. + */ + public int getDeliveryThreads() { + return getDeliveryThreadsActiveMax(); + } + /** + * Sets the number of threads in the thread pool available for mail + * delivery. Currently this does not take effect until the next time the + * system is started and the prefs file is read in. + * + * @param threadCount + * the new number of threads to have available for mail delivery. + * + * @deprecated Use setDeliveryThreadsActiveMax() instead. + * + */ + public void setDeliveryThreads(int threadCount) { + setDeliveryThreadsActiveMax(threadCount); + } + /** + * @return The email address of the postmaster in a MailAddress object. + */ + MailAddress getPostmaster() { + return postmaster; + } + /** + * @deprecated Use setPostmasterEmail() instead. + * @param postmasterAddress + */ + public void setPostmaster(String postmasterAddress) { + setPostmasterEmail(postmasterAddress); + } + /** + * @return int representing the number of times the system will attempt to + * send an e-mail before giving up. + * @deprecated Use getDeliveryAttemptCount() instead. + */ + public int getMaxAttempts() { + return getDeliveryAttemptCount(); + } + /** + * @deprecated Use setDeliveryAttemptCount() instead. + * @param maxAttempts + */ + public void setMaxAttempts(int maxAttempts) { + setDeliveryAttemptCount(maxAttempts); + } + public Log getLog() { + return log; + } + + public String getHostname() { + return hostname; + } + public void setHostname(String hostname) { + this.hostname = hostname; + notifyListeners(PARAM_HOSTNAME); + } + /** + * @deprecated Use isDeliveryDebug() instead. + * @return + */ + public boolean isDebugCommunication() { + return isDeliveryDebug(); + } + /** + * @deprecated Use setDeliveryDebug() instead. + * @param debugCommunication + */ + public void setDebugCommunication(boolean debugCommunication) { + setDeliveryDebug(debugCommunication); + } + public String getEncoding() { + return encoding; + } + public void setEncoding(String encoding) { + this.encoding = encoding; + notifyListeners(PARAM_ENCODING); + } + /** + * @deprecated Use getLoggerPrefix() instead. + * @return + */ + public String getLogPrefix() { + return getLoggerPrefix(); + } + /** + * @deprecated Use setLoggerPrefix() instead. + * @param logPrefix + */ + public void setLogPrefix(String logPrefix) { + setLoggerPrefix(logPrefix); + } + /** + * @deprecated Use getDeliveryTimeout() instead. + * @return + */ + public int getConnectionTimeout() { + return getDeliveryTimeout(); + } + /** + * @deprecated Use setDeliveryTimeout() instead. + * @param connectionTimeout + */ + public void setConnectionTimeout(int connectionTimeout) { + setDeliveryTimeout(connectionTimeout); + } + + @Override + public int getDeliveryAttemptCount() { + return maxAttempts; + } + + @Override + public int getDeliveryAttemptDelay() { + return (int)retryInterval; + } + + @Override + public int getDeliveryThreadsActiveMax() { + return deliveryThreads; + } + + @Override + public int getDeliveryThreadsIdleMax() { + return idleDeliveryThreads; + } + + @Override + public int getDeliveryTimeout() { + return connectionTimeout; + } + + @Override + public String getLoggerName() { + return loggerName; + } + + @Override + public String getLoggerPrefix() { + return loggerPrefix; + } + + @Override + public String getPostmasterEmail() { + return postmaster.toString(); + } + + @Override + public boolean isDeliveryDebug() { + return debugCommunication; + } + + @Override + public void setDeliveryAttemptCount(int attemptCount) { + this.maxAttempts = attemptCount; + notifyListeners(PARAM_DELIVERY_ATTEMPT_COUNT); + } + + @Override + public void setDeliveryAttemptDelay(int delay) { + this.retryInterval = delay; + notifyListeners(PARAM_DELIVERY_ATTEMPT_DELAY); + } + + @Override + public void setDeliveryDebug(boolean debug) { + this.debugCommunication = debug; + notifyListeners(PARAM_DELIVERY_DEBUG); + } + + @Override + public void setDeliveryThreadsActiveMax(int activeThreadsMax) { + this.deliveryThreads = activeThreadsMax; + notifyListeners(PARAM_DELIVERY_THREADS_ACTIVE_MAX); + } + + @Override + public void setDeliveryThreadsIdleMax(int idleThreadsMax) { + this.idleDeliveryThreads = idleThreadsMax; + notifyListeners(PARAM_DELIVERY_THREADS_IDLE_MAX); + } + + @Override + public void setDeliveryTimeout(int timeout) { + this.connectionTimeout = timeout; + notifyListeners(PARAM_DELIVERY_TIMEOUT); + } + + @Override + public void setLoggerName(String loggerName) { + Configuration.loggerName = loggerName; + log = LogFactory.getLog(loggerName); + notifyListeners(PARAM_LOGGER_NAME); + } + + @Override + public void setLoggerPrefix(String loggerPrefix) { + this.loggerPrefix = loggerPrefix; + notifyListeners(PARAM_LOGGER_PREFIX); + } + + @Override + public void setPostmasterEmail(String emailAddress) { + if( emailAddress == null ) + { + this.postmaster = null; + return; + } + try + { + this.postmaster = new MailAddress(emailAddress); + notifyListeners(PARAM_POSTMASTER_EMAIL); + }catch (ParseException e) + { + log.error(getClass().getSimpleName()+".setPostmasterEmail(): The email address is unparseable.", e); + } + } + + public void addListener(ConfigurationChangeListener listener) { + if( listeners == null ) + listeners = new ArrayList(); + synchronized (listeners) { + listeners.add(listener); + } + } + + public void removeListener(ConfigurationChangeListener listener) { + if( listeners != null ) + { + synchronized (listeners) { + listeners.remove(listener); + } + } + } + + private void notifyListeners(String changedParameterName) { + if( listeners != null && 0 < listeners.size() ) + { + if( log.isInfoEnabled() ) + log.info(getClass().getSimpleName()+".notifyListeners(): Configuration parameter '"+changedParameterName+"' changed."); + synchronized (listeners) { + for( ConfigurationChangeListener listener : listeners ) + listener.configChanged(changedParameterName); + } + } + } + +} \ No newline at end of file Index: 3rdParty_sources/aspirin/org/masukomi/aspirin/core/ConfigurationChangeListener.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/masukomi/aspirin/core/ConfigurationChangeListener.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/masukomi/aspirin/core/ConfigurationChangeListener.java 17 Aug 2012 14:15:37 -0000 1.1 @@ -0,0 +1,18 @@ +package org.masukomi.aspirin.core; + +/** + *

This interface is part of configuration subsystem. If a configuration + * parameter was changed, the classes which implements this interface could be + * notified about these changes. It is requried to allow immediately dynamic + * configuration.

+ * + * @version $Id: ConfigurationChangeListener.java,v 1.1 2012/08/17 14:15:37 marcin Exp $ + * + */ +interface ConfigurationChangeListener { + /** + * This method is called when a configuration parameter is changed. + * @param parameterName Name of changed parameter. + */ + public void configChanged(String parameterName); +} Index: 3rdParty_sources/aspirin/org/masukomi/aspirin/core/ConfigurationMBean.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/masukomi/aspirin/core/ConfigurationMBean.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/masukomi/aspirin/core/ConfigurationMBean.java 17 Aug 2012 14:15:38 -0000 1.1 @@ -0,0 +1,148 @@ +package org.masukomi.aspirin.core; + +import java.io.File; + +import javax.mail.Transport; + +/** + *

This is the JMX bean of Aspirin configuration. Some configuration + * parameter could be applied immediately.

+ * + * @version $Id: ConfigurationMBean.java,v 1.1 2012/08/17 14:15:38 marcin Exp $ + * + */ +public interface ConfigurationMBean { + + public static final String PARAM_DELIVERY_ATTEMPT_DELAY = "aspirin.delivery.attempt.delay"; + public static final String PARAM_DELIVERY_ATTEMPT_COUNT = "aspirin.delivery.attempt.count"; + public static final String PARAM_DELIVERY_DEBUG = "aspirin.delivery.debug"; + public static final String PARAM_DELIVERY_THREADS_ACTIVE_MAX = "aspirin.delivery.threads.active.max"; + public static final String PARAM_DELIVERY_THREADS_IDLE_MAX = "aspirin.delivery.threads.idle.max"; + public static final String PARAM_DELIVERY_TIMEOUT = "aspirin.delivery.timeout"; + public static final String PARAM_ENCODING = "aspirin.encoding"; + public static final String PARAM_HOSTNAME = "aspirin.hostname"; + public static final String PARAM_LOGGER_NAME = "aspirin.logger.name"; + public static final String PARAM_LOGGER_PREFIX = "aspirin.logger.prefix"; + public static final String PARAM_POSTMASTER_EMAIL = "aspirin.postmaster.email"; + + /** + * @return The time between two delivery attempt of an email. + */ + public int getDeliveryAttemptDelay(); + /** + * @return The maximal count of delivery attempts of an email. + */ + public int getDeliveryAttemptCount(); + /** + * @return The maximal count of delivery threads running paralel. + */ + public int getDeliveryThreadsActiveMax(); + /** + * @return The maximal count of delivery threads stored as idle in delivery + * pool. + */ + public int getDeliveryThreadsIdleMax(); + /** + * @return The socket and {@link Transport} timeout in a delivery. + */ + public int getDeliveryTimeout(); + /** + * @return The name of MIME encoding of emails. + */ + public String getEncoding(); + /** + * @return The name of the logger. + */ + public String getLoggerName(); + /** + * @return The prefix appended to the start of the log entries. + */ + public String getLoggerPrefix(); +// /** +// * @return The directory object where the mimemessage objects could be +// * stored. +// */ +// public File getMailCacheDirectory(); + /** + * @return The email address of the postmaster. + */ + public String getPostmasterEmail(); + /** + * @return The hostname of this server. It is used in HELO SMTP command. + */ + public String getHostname(); + /** + * @return If true, then the full SMTP communication will be logged. + */ + public boolean isDeliveryDebug(); + /** + * Set the time interval between two delivery attempts of a temporary + * undeliverable email. + * @param delay The value of delay in milliseconds. + */ + public void setDeliveryAttemptDelay(int delay); + /** + * Set the maximal count of delivery tries of a temporary undeliverable + * email. + * @param attemptCount The count of deliery attempts. + */ + public void setDeliveryAttemptCount(int attemptCount); + /** + * Set the debug of full SMTP communication. + * @param debug If true, then the full communication will be logged. + */ + public void setDeliveryDebug(boolean debug); + /** + * Set the maximal count of paralel running delivery threads. + * @param threadsCount The count of delivery threads. + */ + public void setDeliveryThreadsActiveMax(int activeThreadsMax); + /** + * Set the maximal count of idle delivery threads stored in pool. + * @param threadsCount The count of delivery threads. + */ + public void setDeliveryThreadsIdleMax(int idleThreadsMax); + /** + * Set the timeout of {@link Transport} and Socket which is used if + * communication is too slow. + * @param timeout The value of timeout in milliseconds. + */ + public void setDeliveryTimeout(int timeout); + /** + * Set the encoding of MIME messages. For example: "UTF-8". + * @param encoding The MIME encoding. + */ + public void setEncoding(String encoding); + /** + * If you have got an own logger, you can set up a logger name, which is + * used in your system. + * @param loggerName The name of your logger. + */ + public void setLoggerName(String loggerName); + /** + * Set the logger prefix, which will be appended to the start of log + * entries. + * @param loggerPrefix The prefix string. + */ + public void setLoggerPrefix(String loggerPrefix); +// /** +// * +// * @param mailCacheDirectory +// */ +// public void setMailCacheDirectory(File mailCacheDirectory); + /** + * Set the email address of postmaster. If delivery failed, you can get an + * email about the failure to this address. + * @param emailAddress The email address of postmaster. + */ + public void setPostmasterEmail(String emailAddress); + /** + * Set the hostname, which is used in HELO command of SMTP communication. + * This hostname identifies us for other hosts. If the hostname is invalid + * or not correctly configured for this server, the delivery could be + * failed in various reasons. + * @param hostname The name of this server or application. + */ + public void setHostname(String hostname); + +} Index: 3rdParty_sources/aspirin/org/masukomi/aspirin/core/GenericPoolableRemoteDeliveryFactory.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/masukomi/aspirin/core/GenericPoolableRemoteDeliveryFactory.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/masukomi/aspirin/core/GenericPoolableRemoteDeliveryFactory.java 17 Aug 2012 14:15:38 -0000 1.1 @@ -0,0 +1,80 @@ +package org.masukomi.aspirin.core; + +import org.apache.commons.pool.BasePoolableObjectFactory; +import org.apache.commons.pool.ObjectPool; + +/** + *

This object handles the RemoteDelivery thread objects in the ObjectPool. + *

+ * + * @version $Id: GenericPoolableRemoteDeliveryFactory.java,v 1.1 2012/08/17 14:15:38 marcin Exp $ + * + */ +public class GenericPoolableRemoteDeliveryFactory extends BasePoolableObjectFactory { + + /** + * This is the ThreadGroup of RemoteDelivery objects. On shutdown it is + * easier to close all RemoteDelivery threads with usage of this group. + */ + private ThreadGroup remoteDeliveryThreadGroup = null; + private ObjectPool myParentPool = null; + + /** + * This is the counter of created RemoteDelivery thread objects. + */ + private Integer rdCount = 0; + + /** + *

Initialization of this Factory. Prerequisite of right working.

+ * + * @param deliveryThreadGroup The threadgroup which contains the + * RemoteDelivery threads. + * @param pool The pool which use this factory to create and handle objects. + */ + public void init(ThreadGroup deliveryThreadGroup, ObjectPool pool) { + remoteDeliveryThreadGroup = deliveryThreadGroup; + myParentPool = pool; + } + + @Override + public Object makeObject() throws Exception { + if( myParentPool == null ) + throw new RuntimeException("Please set the parent pool for right working."); + RemoteDelivery rd = new RemoteDelivery(remoteDeliveryThreadGroup); + synchronized (rdCount) { + rdCount++; + rd.setName(RemoteDelivery.class.getSimpleName()+"-"+rdCount); + } + rd.setParentPool(myParentPool); + Configuration.getInstance().getLog().trace(getClass().getSimpleName()+".makeObject(): New RemoteDelivery object created: "+rd.getName()); + /* + * This will be started after first borrow of this object, because the + * first item to process will be set after first borrow too. + */ +// rd.start(); + Configuration.getInstance().addListener(rd); + return rd; + } + + @Override + public void destroyObject(Object obj) throws Exception { + if( obj instanceof RemoteDelivery ) + { + RemoteDelivery rd = (RemoteDelivery)obj; + Configuration.getInstance().getLog().trace(getClass().getSimpleName()+".destroyObject(): destroy thread "+rd.getName()); + rd.shutdown(); + Configuration.getInstance().removeListener(rd); + } + } + + @Override + public boolean validateObject(Object obj) { + if( obj instanceof RemoteDelivery ) + { + RemoteDelivery rd = (RemoteDelivery)obj; + return rd.isAlive(); + } + return false; + } + +} Index: 3rdParty_sources/aspirin/org/masukomi/aspirin/core/MXLookup.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/masukomi/aspirin/core/MXLookup.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/masukomi/aspirin/core/MXLookup.java 17 Aug 2012 14:15:38 -0000 1.1 @@ -0,0 +1,129 @@ +/* + * Created on May 19, 2004 + * + * This class was based on a method in JMTA.java by Rapha�l Szwarc + * + * + * CURRENTLY UNUSED BECAUSE JNDI KEEPS TIMING OUT FOR SOME DOMAINS + * + */ +// +//=========================================================================== +// +//Title: JMTA.java +//Description: [Description] +//Author: Rapha�l Szwarc +//Creation Date: Tue May 18 2004 +//Legal: Copyright (C) 2004 Rapha�l Szwarc +// +//This software is provided 'as-is', without any express or implied warranty. +//In no event will the author be held liable for any damages arising from +//the use of this software. +// +//Permission is granted to anyone to use this software for any purpose, +//including commercial applications, and to alter it and +//redistribute it freely, subject to the following restrictions: +// +//1. The origin of this software must not be misrepresented; +//you must not claim that you wrote the original software. +//If you use this software in a product, an acknowledgment +//in the product documentation would be appreciated but is not required. +// +//2. Altered source versions must be plainly marked as such, +//and must not be misrepresented as being the original software. +// +//3. This notice may not be removed or altered from any source distribution. +// +//--------------------------------------------------------------------------- +package org.masukomi.aspirin.core; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Hashtable; +import java.util.List; + +import javax.mail.URLName; +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.Attributes; +import javax.naming.directory.DirContext; +import javax.naming.directory.InitialDirContext; + +import org.apache.commons.logging.Log; +/** + * @author masukomi + * + * TODO To change the template for this generated type comment go to Window - + * Preferences - Java - Code Generation - Code and Comments + * + * @deprecated Unused + */ +public class MXLookup { + private static final Log log = Configuration.getInstance().getLog(); + private static final String[] DNSRecords = {"MX"}; + private static final String DNSScheme = "dns://"; //was dns:/ + private static final String SMTPScheme = "smtp://"; + private static Hashtable env; + + // Unused + static public Collection urlsForHost(final String host) + throws NamingException { + if (host != null && !host.equals("")) { + + if (log.isTraceEnabled()){ + log.trace("looking up mx records for "+host); + } + List serviceURLsList = new ArrayList(); + String aQuery = MXLookup.DNSScheme + host; + if (env == null){ + env = new Hashtable(); + env.put("com.sun.jndi.dns.timeout.initial", "60000"); + //env.put("com.sun.jndi.dns.timeout.retries", "3"); + env.put("com.sun.jndi.dns.recursion", "true"); + } + + DirContext dirContext = new InitialDirContext(env); + + Attributes dnsAttributes = dirContext.getAttributes(aQuery, + MXLookup.DNSRecords); + for (NamingEnumeration anEnumeration = dnsAttributes.getIDs(); anEnumeration + .hasMore();) { + String anID = (String) anEnumeration.next(); + Attribute anAttribute = dnsAttributes.get(anID); + int count = anAttribute.size(); + + int anIndex; + for (int index = 0; index < count; index++) { + Object aValue = anAttribute.get(index); + if (aValue != null) { + anIndex = ((String) aValue).indexOf(' '); + if (anIndex > 0) { + String aService = ((String) aValue) + .substring(anIndex + 1); + URLName aServiceURL = new URLName( + MXLookup.SMTPScheme + aService); + serviceURLsList.add(aServiceURL); + } + } + }// END for (int index = 0; index < count; index++) + } // END for (NamingEnumeration anEnumeration = + // someAttributes + // .getIDs(); anEnumeration.hasMore();) + dirContext.close(); + if (!serviceURLsList.isEmpty()) { + //Collections.shuffle(serviceURLsList); + //return (URLName) serviceURLsList.get(0); + return serviceURLsList; + } + ArrayList defaultArrayList = new ArrayList(); + defaultArrayList.add(new URLName(MXLookup.SMTPScheme + host)); + return defaultArrayList; + } + throw new IllegalArgumentException( + "MXLookup.urlForAddress: null address."); + } + // Unused + static public void setJNDIEnvironment(Hashtable environment){ + env = environment; + } +} \ No newline at end of file Index: 3rdParty_sources/aspirin/org/masukomi/aspirin/core/MailQue.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/masukomi/aspirin/core/MailQue.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/masukomi/aspirin/core/MailQue.java 17 Aug 2012 14:15:37 -0000 1.1 @@ -0,0 +1,309 @@ +/* + * Created on Jan 3, 2004 + * + * Copyright (c) 2004 Katherine Rhodes (masukomi at masukomi dot org) + * + * 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. + * + * @author kate rhodes + * @author Brian Schultheiss + * + * Much thanks to Brian for fixing the multiple recepient bug. + */ +package org.masukomi.aspirin.core; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.Vector; + +import javax.mail.MessagingException; +import javax.mail.internet.AddressException; +import javax.mail.internet.MimeMessage; + +import org.apache.commons.logging.Log; +import org.apache.james.core.MailImpl; + +/** + *

This class represents the mailing queue of the Aspirin.

+ * + * @author masukomi + * @version $Id: MailQue.java,v 1.1 2012/08/17 14:15:37 marcin Exp $ + * + */ +public class MailQue { + private Log log = Configuration.getInstance().getLog(); + protected QueManager qm; + protected Vector que; + protected Vector listeners; +// MailQue mq; + private Vector listenersToRemove; + private Vector listenersToAdd; + private int notificationCount; + + public MailQue() { + qm = new QueManager(this); + que = new Vector(); + listeners = new Vector(); + listenersToRemove = new Vector(); + listenersToAdd = new Vector(); + notificationCount = 0; + } + public void queMail(MimeMessage message) throws MessagingException { + service(message, getListeners()); + notifyQueManager(); + } + protected void service(MimeMessage mimeMessage, Collection watchers) + throws AddressException, MessagingException { + + MailImpl sourceMail = new MailImpl(mimeMessage); + // Do I want to give the internal key, or the message's Message ID + if (log.isDebugEnabled()) + log.debug(getClass().getSimpleName()+".service(): Remotely delivering mail " + sourceMail.getName()); + + /* + * We don't need to organize recipients and separate into unique mails. + * The RemoteDelivery could handle a mail with multiple recipients and + * target servers. + */ + +// Collection recipients = sourceMail.getRecipients(); + // Must first organize the recipients into distinct servers (name made + // case insensitive) +// Hashtable> targets = new Hashtable>(); +// for (Iterator i = recipients.iterator(); i.hasNext();) { +// MailAddress target = (MailAddress) i.next(); +// String targetServer = target.getHost().toLowerCase(Locale.US); +// //Locale.US because only ASCII supported in domains? -kate +// +// //got any for this domain yet? +// Vector temp = targets.get(targetServer); +// if (temp == null) { +// temp = new Vector(); +// targets.put(targetServer, temp); +// } +// temp.add(target); +// } + //We have the recipients organized into distinct servers... put them + // into the + //delivery store organized like this... this is ultra inefficient I + // think... + // Store the new message containers, organized by server, in the que + // mail repository +// for (Iterator i = targets.keySet().iterator(); i.hasNext();) { +// //make a copy of it for each recipient +// MailImpl uniqueMail = new MailImpl(mimeMessage); +// String name = uniqueMail.getName(); +// String host = (String) i.next(); +// Vector rec = targets.get(host); +// if (log.isDebugEnabled()) { +// StringBuffer logMessageBuffer = new StringBuffer(128).append( +// "Sending mail to ").append(rec).append(" on host ") +// .append(host); +// log.debug(logMessageBuffer.toString()); +// } +// uniqueMail.setRecipients(rec); +// StringBuffer nameBuffer = new StringBuffer(128).append(name) +// .append("-to-").append(host); +// uniqueMail.setName(nameBuffer.toString()); +// store(new QuedItem(uniqueMail)); +// //Set it to try to deliver (in a separate thread) immediately +// // (triggered by storage) +// uniqueMail.setState(Mail.GHOST); +// } +// } + // TODO Prioritaire email + QuedItem qi = new QuedItem(sourceMail, this); + synchronized (this) { + getQue().add(qi); + } + } + // Unused +// protected void store(QuedItem qi) { +// getQue().add(qi); +// // try and send it +// } + /** + * It gives back the next item to send and removes all completed items. + * + * @return The next item to send, or null, if no such item exists. + */ + public synchronized QuedItem getNextSendable() { + if( getQue().size() <= 0 ) + return null; + + Collections.sort(getQue()); + + Vector itemsToRemove = new Vector(); + QuedItem itemToSend = null; + +// Iterator it = getQue().iterator(); + for( QuedItem qi : getQue() ) + { + if( qi.isCompleted() ) + { + itemsToRemove.add(qi); + continue; + }else + if( qi.isReadyToSend() ) + { + itemToSend = qi; + break; + } + } + // if we've made it this far there are no mails waiting to send + // let's clean out the old mails. +// Vector que = getQue(); +// if (que.size() > 0) { +// for (QuedItem qi : getQue()){ +// if (qi.getStatus() == QuedItem.COMPLETED){ +// itemsToRemove.add(qi); +// } +// } + if( log.isTraceEnabled() ) + log.trace(getClass().getSimpleName()+".getNextSendable(): Maintenance of MailQue - removed "+itemsToRemove.size()+" items from "+getQue().size()); + getQue().removeAll(itemsToRemove); + if( log.isTraceEnabled() && 0 < itemsToRemove.size() ) + log.trace(getClass().getSimpleName()+".getNextSendable(): Remove all items: "+itemsToRemove); +// } + // Lock QuedItem + if( itemToSend != null ) + { + log.trace(getClass().getSimpleName()+".getNextSendable(): Found item to send. qi="+itemToSend); + itemToSend.lock(); + } + return itemToSend; + } + + public int getQueueSize() { + return getQue().size(); + } + + /** + * Occasionally a QuedItem will be dropped from the Que. This method will + * re-insert it. + * + * @param item + */ + public synchronized void reQue(QuedItem item) { + if( getQue().indexOf(item) == -1 ) + { + getQue().add(item); + notifyQueManager(); + } + } + QueManager getQueManager() { + synchronized (qm) { + if (qm == null) + { + qm = new QueManager(this); + } + } + return qm; + } + + /** + * PUBLIC FOR TESTING ONLY + * TODO public -> private + * @return + */ + public Vector getQue() { + return que; + } + + public void addWatcher(MailWatcher watcher) { + if (! isNotifying()) { + getListeners().add(watcher); + } else { + getQueManager().pauseNewSends(); + listenersToAdd.add(watcher); + } + } + + public void removeWatcher(MailWatcher watcher) { + if (!isNotifying()) { + getListeners().remove(watcher); + } else { + getQueManager().pauseNewSends(); + listenersToRemove.add(watcher); + } + } + public Vector getListeners() { + return listeners; + } + public synchronized void incrementNotifiersCount() { + notificationCount++; + } + /** + * decrements the number of notifiers currently happening and if there are + * none in progress it will add or remove watchers as appropriate + * + */ + public synchronized void decrementNotifiersCount() { + notificationCount--; + if (notificationCount == 0) { + Iterator removersIt = listenersToRemove.iterator(); + while (removersIt.hasNext()) { + listeners.add(removersIt.next()); + } + listenersToRemove.clear(); + Iterator addersIt = listenersToAdd.iterator(); + while (addersIt.hasNext()) { + listeners.add(addersIt.next()); + } + listenersToAdd.clear(); + getQueManager().unPauseNewSends(); + } + } + /** + * @return Returns the notifying. + */ + public synchronized boolean isNotifying() { + return notificationCount != 0; + } + + public synchronized void terminate() { + if( qm != null ) + { + synchronized (qm) { + qm.terminateRun(); + } + } + } + + void resetQueManager() { + if( qm != null ) + { + synchronized (qm) { + qm.terminateRun(); + qm = null; + } + } + } + + /** + * + */ + private void notifyQueManager() { + if( !getQueManager().isRunning() ) + getQueManager().start(); + else + getQueManager().notifyWithMail(); + } + +} \ No newline at end of file Index: 3rdParty_sources/aspirin/org/masukomi/aspirin/core/MailWatcher.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/masukomi/aspirin/core/MailWatcher.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/masukomi/aspirin/core/MailWatcher.java 17 Aug 2012 14:15:38 -0000 1.1 @@ -0,0 +1,43 @@ +/* + * Created on Jan 5, 2004 + * + * Copyright (c) 2004 Katherine Rhodes (masukomi at masukomi dot org) + +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. + */ +package org.masukomi.aspirin.core; + +import javax.mail.MessagingException; +import javax.mail.internet.MimeMessage; + +import org.apache.mailet.MailAddress; +/** + *

This is a listener interface. This defines the mail delivery listeners, + * which could get messages if an email is delivered to a recipient (with the + * delivery result) and if an email is delivered to all recipients.

+ * + * @author kate rhodes, masukomi at masukomi dot org + * + * @version $Id: MailWatcher.java,v 1.1 2012/08/17 14:15:38 marcin Exp $ + * + */ +public interface MailWatcher { + public void deliverySuccess(MailQue que, MimeMessage message, MailAddress recipient); + public void deliveryFailure(MailQue que, MimeMessage message, MailAddress recipient, MessagingException mex); + public void deliveryFinished(MailQue que, MimeMessage message); +} Index: 3rdParty_sources/aspirin/org/masukomi/aspirin/core/QueManager.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/masukomi/aspirin/core/QueManager.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/masukomi/aspirin/core/QueManager.java 17 Aug 2012 14:15:38 -0000 1.1 @@ -0,0 +1,250 @@ +/* + * Created on Jan 3, 2004 + * + * Copyright (c) 2004 Katherine Rhodes (masukomi at masukomi dot org) + * + * 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. + * + */ +package org.masukomi.aspirin.core; + +import org.apache.commons.logging.Log; +import org.apache.commons.pool.ObjectPool; +import org.apache.commons.pool.impl.GenericObjectPool; + +/** + *

This object is the manager, the main class of mail delivering.

+ * + *

+ * + * Iterates over the items in a MailQue and sends them all out. + * + * Please note, that in an effort to address some threading issues + * this class no longer utilizes a ThreadPool. Instead it sends the items + * in the MailQue out sequentially. + * + * @author masukomi + * + * @version $Id: QueManager.java,v 1.1 2012/08/17 14:15:38 marcin Exp $ + * + */ +class QueManager extends Thread implements ConfigurationChangeListener { + + private boolean running = false; + private ObjectPool remoteDeliveryObjectPool = null; + protected MailQue que; + + static private Log log = Configuration.getInstance().getLog(); + protected boolean pauseNewSends = false; + + /** + * Iterates over the items in a MailQue and sends them all out. + * + * @param que + */ + public QueManager(MailQue que) { + // Set up default objects. + this.que = que; + this.setName("Aspirin-"+getClass().getSimpleName()+"-"+getId()); + + // Configure pool of RemoteDelivery threads + GenericObjectPool.Config gopConf = new GenericObjectPool.Config(); + gopConf.lifo = false; + gopConf.maxActive = Configuration.getInstance().getDeliveryThreadsActiveMax(); + gopConf.maxIdle = Configuration.getInstance().getDeliveryThreadsIdleMax(); + gopConf.maxWait = 5000; + gopConf.testOnReturn = true; + gopConf.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK; + + // Create RemoteDelivery object factory used in pool + GenericPoolableRemoteDeliveryFactory remoteDeliveryObjectFactory = new GenericPoolableRemoteDeliveryFactory(); + + // Create pool + remoteDeliveryObjectPool = new GenericObjectPool( + remoteDeliveryObjectFactory, + gopConf + ); + + // Initialize object factory of pool + remoteDeliveryObjectFactory.init( + new ThreadGroup("RemoteDeliveryThreadGroup"), + remoteDeliveryObjectPool + ); + + Configuration.getInstance().addListener(this); + + } + + + /** + * @return Returns true if the thread is running + */ + public boolean isRunning() { + return running; + } + /** + * Terminates the current run. May + * + */ + public void terminateRun() { + running = false; + synchronized (this) { + notifyAll(); + } + } + public boolean isTerminated(){ + return running; + } + public void pauseNewSends() { + pauseNewSends = true; + } + public void unPauseNewSends() { + pauseNewSends = false; + } + + public boolean isPaused() { + return pauseNewSends; + } + /** + * DOCUMENT ME! + */ + public void run() { + running = true; +// terminateRun = false; + // if we're HERE then run has JUST + // been called, and obviously someone wants us to run, + // which we can't do if we're terminated. + // this will frequently need to be flipped back like this + // if you're restarting a QueManager that has already been + // through a cycle. + log.info(getClass().getSimpleName()+".run(): QueManager started."); + while (running) + { + if( !isPaused() ) + { + QuedItem qi = null; + try + { + qi = getQue().getNextSendable(); + if( qi != null ) + { + try + { + if( log.isDebugEnabled() ) + log.debug(getClass().getSimpleName()+".run(): Start delivery. qi="+qi); + + RemoteDelivery rd = (RemoteDelivery)remoteDeliveryObjectPool.borrowObject(); + if( log.isTraceEnabled() ) + { + log.trace(getClass().getSimpleName()+".run(): Borrow RemoteDelivery object. rd="+rd.getName()); + log.trace(getClass().getSimpleName()+".run(): Pool state. A"+remoteDeliveryObjectPool.getNumActive()+"/I"+remoteDeliveryObjectPool.getNumIdle()); + } + rd.setQuedItem(qi); + /* + * On first borrow the RemoteDelivery is created and + * initialized, but not started, because the first + * time we have to set up the QueItem to deliver. + */ + if( !rd.isAlive() ) + { + rd.setQue(que); + rd.start(); + } + } catch (Exception e) + { + log.error(getClass().getSimpleName()+".run(): Failed borrow delivery thread object.",e); + log.trace(getClass().getSimpleName()+".run(): Pool state. A"+remoteDeliveryObjectPool.getNumActive()+"/I"+remoteDeliveryObjectPool.getNumIdle()); + qi.release(); + } + } else + { + if( log.isTraceEnabled() && 0 < getQue().getQueueSize() ) + log.trace(getClass().getSimpleName()+".run(): There is no sendable item in the queue. Fallback to waiting state for a minute."); + synchronized (this) { + try + { + /* + * We should wait for a specified time, because + * some emails unsent could be sendable again. + */ + wait(60000); + }catch (InterruptedException e) + { + running = false; + // Before stopping QueManager remove it from MailQue. + que.resetQueManager(); + return; + } + } + } + }catch (Throwable t) + { + log.error(getClass().getSimpleName()+".run(): Sending of QueItem failed. qi="+qi, t); + if( qi != null ) + qi.release(); + } + } + } + try + { + remoteDeliveryObjectPool.clear(); + }catch (Exception e) + { + log.error(getClass().getSimpleName()+".run(): Could not clear remote delivery pool.", e); + } + log.info(getClass().getSimpleName()+".run(): QueManager closed."); + } + + public MailQue getQue() { + return que; + } + + + public void setQue(MailQue que) { + this.que = que; + } + + public ObjectPool getRemoteDeliveryObjectPool() { + return remoteDeliveryObjectPool; + } + + public synchronized void notifyWithMail() { + notify(); + } + + + @Override + public void configChanged(String parameterName) { + if( ConfigurationMBean.PARAM_DELIVERY_THREADS_ACTIVE_MAX.equals(parameterName) ) + { + ((GenericObjectPool)remoteDeliveryObjectPool).setMaxActive(Configuration.getInstance().getDeliveryThreadsActiveMax()); + }else + if( ConfigurationMBean.PARAM_DELIVERY_THREADS_IDLE_MAX.equals(parameterName) ) + { + ((GenericObjectPool)remoteDeliveryObjectPool).setMaxIdle(Configuration.getInstance().getDeliveryThreadsIdleMax()); + } + } + + @Override + protected void finalize() throws Throwable { + Configuration.getInstance().removeListener(this); + super.finalize(); + } + +} Index: 3rdParty_sources/aspirin/org/masukomi/aspirin/core/QuedItem.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/masukomi/aspirin/core/QuedItem.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/masukomi/aspirin/core/QuedItem.java 17 Aug 2012 14:15:37 -0000 1.1 @@ -0,0 +1,318 @@ +/* + * Created on Jan 5, 2004 + * + * Copyright (c) 2004 Katherine Rhodes (masukomi at masukomi dot org) + * + * 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. + */ +package org.masukomi.aspirin.core; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; + +import javax.mail.MessagingException; + +import org.apache.commons.logging.Log; +import org.apache.james.core.MailImpl; +import org.apache.mailet.Mail; +import org.apache.mailet.MailAddress; +/** + * A QuedItem contains a Mail object, a list of MailWatchers, and assorted + * variables to manage it's place in the que and retries. + * + * @author kate rhodes masukomi at masukomi dot org + * + * @version $Id: QuedItem.java,v 1.1 2012/08/17 14:15:37 marcin Exp $ + * + */ +public class QuedItem implements Comparable { + static private Log log = Configuration.getInstance().getLog(); + /** A Collection of MailWatchers */ + //protected Collection watchers; + /** The mail to be sent */ + protected Mail mail; + + /** DOCUMENT ME! */ + protected long nextAttempt; + private static final int IN_QUE = 0; + private static final int IN_PROCESS = 1; + private static final int COMPLETED = 3; + protected Integer status = IN_QUE; + protected HashMap recipientFailures; + protected HashMap recipientSuccesses; + protected int numSuccesses; + protected int numFailures; + /** + * + */ + public QuedItem(Mail mail, MailQue que) { + this.mail = mail; + //this.watchers = listeners; + nextAttempt = System.currentTimeMillis(); + } + /** + * + * + * @return the Mail message + */ + public Mail getMail() { + return mail; + } + /** + * + * + * @return The time in milliseconds when the system will next be able to attempt a resend of this mail + */ + public long getNextAttempt() { + return nextAttempt; + } + /** + * @deprecated + * + * @return zero This method is no longer applicable + */ + public int getNumAttempts() { + return 0; + } + /** + * Used to sort items by their next attempt time + * + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + @Override + public int compareTo(QuedItem qi) { +// try +// { + return (int)Math.signum(getNextAttempt() - qi.getNextAttempt()); +// if (qi.getNextAttempt() > getNextAttempt()) +// { +// return -1; +// }else +// if (qi.getNextAttempt() < getNextAttempt()) +// { +// return 1; // that one should go first +// } +// return 0; +// }catch (ClassCastException cce) +// { +// return 0; +// } + } + /** + * Sends a failure notice to any watchers about the current mail and recipient. + */ + public void failForRecipient(MailQue que, MailAddress recipient, MessagingException mex) { + numFailures++; + if (recipientFailures == null) { + recipientFailures = new HashMap(); + } + recipientFailures.put(recipient, + new Integer(Configuration.getInstance().getDeliveryAttemptCount())); + // tell anyone who cares + if (que.getListeners() != null) { + que.incrementNotifiersCount(); + for (MailWatcher watcher : que.getListeners()){ + try { + watcher.deliveryFailure(que, getMail().getMessage(), recipient, mex); + if( isCompleted() ) + watcher.deliveryFinished(que, getMail().getMessage()); + } catch (MessagingException e) { + log.error(getClass().getSimpleName()+".failForRecipient(): ",e); + } + } + que.decrementNotifiersCount(); + //TODO: is that right? I mean, just because it failed for + // one recipient it doesn't mean the message is done sending + + } + // It will be released after processing +// release(); +// if (isCompleted()) { +// +// setStatus(COMPLETED); +// //this will flag it for removal from the que +// } + } + /** + * DOCUMENT ME! + */ + public void retry(MailQue que, MailAddress recipient) { + que.reQue(this); // just in case + if (retryable(recipient)) { + // increment it's number of failures + if (recipientFailures.containsKey(recipient)) { + Integer numFailures = (Integer) recipientFailures.get(recipient); + recipientFailures.put(recipient, new Integer(numFailures.intValue() +1)); + } else { + recipientFailures.put(recipient, new Integer(1)); + } + + + + + nextAttempt = System.currentTimeMillis() + Configuration.getInstance().getDeliveryAttemptDelay(); + // It will be released after processing +// release(); +// setStatus(QuedItem.IN_QUE); + if (log.isTraceEnabled()) { + log.trace(getClass().getSimpleName()+".retry(): will retry message at " + + new Date(nextAttempt).toString()); + } + } else { + try { + failForRecipient(que, recipient, null); + Bouncer.bounce(que, getMail(), "Maxumum retries exceeded for " +recipient, + Configuration.getInstance().getPostmaster()); + } catch (MessagingException e) { + log.error(getClass().getSimpleName()+".retry(): ",e); + } + } + } +// /** +// * @param i +// */ +// public void setStatus(int i) { +// status = i; +// } + + public void lock() { + synchronized (status) { + status = IN_PROCESS; + } + } + + public void release() { + synchronized (status) { + if( isCompleted() ) + status = COMPLETED; + else + status = IN_QUE; + log.trace(getClass().getSimpleName()+".release(): Item released. qi="+this); + } + } + + /** + * @return true if the current recipient can be retried again + */ + public boolean retryable(MailAddress recipient) { + if (recipientFailures == null) { + recipientFailures = new HashMap(); + } + if (recipientFailures.containsKey(recipient)) { + Integer numFailures = (Integer) recipientFailures.get(recipient); + if ((numFailures.intValue() + 1) < Configuration.getInstance() + .getDeliveryAttemptCount()) { + return true; + } + } else { + return true; + } + return false; + } + + /** + * @return Returns the status. + */ + public int getStatus() { + return status; + } + /** + * @return true if this message is ready to be retried + */ + public boolean isReadyToSend() { + if (getStatus() != QuedItem.IN_QUE) { + return false; + } + if (nextAttempt > System.currentTimeMillis()) { + return false; // let's let this one cook a bit longer. + } + // could test if retryable in here but theoretically it can't not be + return true; + } + /* + * public Collection getWatchers(){ return watchers; } + */ + /** + * called by RemoteDelivery when it successfully sends a message to a + * particular recipient + */ + public void succeededForRecipient(MailQue que, MailAddress recipient) { + numSuccesses++; + if (recipientSuccesses == null) { + recipientSuccesses = new HashMap(); + } + recipientSuccesses.put(recipient, null); + + if (que.getListeners() != null + && que.getListeners().size() > 0) { + que.incrementNotifiersCount(); + Iterator it = que.getListeners().iterator(); + while (it.hasNext()) { + MailWatcher watcher = it.next(); + try { + //watcher.deliverySuccess(getMail().getMessage(), recipients); + watcher.deliverySuccess(que, getMail().getMessage(), recipient); + if( isCompleted() ) + watcher.deliveryFinished(que, getMail().getMessage()); + } catch (MessagingException e) { + log.error(getClass().getSimpleName()+"succeededForRecipient(): ",e); + } + } + que.decrementNotifiersCount(); + } + // It will be released after processing +// release(); +// if (isCompleted()) { +// setStatus(COMPLETED); +// // this will flag it for removal from the que +// } + } + boolean isCompleted() { + int recipientsCount = getMail().getRecipients().size(); + if( log != null && log.isTraceEnabled() ) + log.trace(getClass().getSimpleName()+" ("+((MailImpl)getMail()).getName()+").isCompleted(): S"+numSuccesses+"+F"+numFailures+"/A"+recipientsCount); + if (numSuccesses + numFailures >= recipientsCount) { + return true; + } + return false; + } + + boolean recepientHasBeenHandled(MailAddress recipient) { + if (recipientSuccesses != null && recipientSuccesses.containsKey(recipient)) { + return true; + } + + if (recipientFailures != null && recipientFailures.containsKey(recipient) && ((Integer)recipientFailures.get(recipient)).intValue() >2) { + return true; + } + return false; + + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()).append(" ["); + sb.append("id=").append(((MailImpl)getMail()).getName()).append("; "); + sb.append("status=").append(status).append("; "); + sb.append("]; "); + return sb.toString(); + } + +} Index: 3rdParty_sources/aspirin/org/masukomi/aspirin/core/RemoteDelivery.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/masukomi/aspirin/core/RemoteDelivery.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/masukomi/aspirin/core/RemoteDelivery.java 17 Aug 2012 14:15:38 -0000 1.1 @@ -0,0 +1,839 @@ +/* + * ==================================================================== The + * Apache Software License, Version 1.1 + * + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if and + * wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache", "Jakarta", "JAMES" and "Apache Software Foundation" + * must not be used to endorse or promote products derived from this software + * without prior written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the Apache + * Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE + * SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many individuals on + * behalf of the Apache Software Foundation. For more information on the Apache + * Software Foundation, please see . + * + * Portions of this software are based upon public domain software originally + * written at the National Center for Supercomputing Applications, University of + * Illinois, Urbana-Champaign. + * + * + */ +/** + * This class does the actual work of delivering the mail to the intended + * recepient. It is the class of the same name from James with some + * modifications. + * + * @author kate rhodes masukomi at masukomi dot org + * + * + */ +//TODO make retries be based on recepients not QuedItems +package org.masukomi.aspirin.core; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.Arrays; +import java.util.Collection; +import java.util.Comparator; +import java.util.Date; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Properties; +import java.util.Vector; + +import javax.mail.Address; +import javax.mail.MessagingException; +import javax.mail.SendFailedException; +import javax.mail.Session; +import javax.mail.Transport; +import javax.mail.URLName; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; +import javax.mail.internet.ParseException; + +import org.apache.commons.logging.Log; +import org.apache.commons.pool.ObjectPool; +import org.apache.james.core.MailImpl; +import org.apache.mailet.Mail; +import org.apache.mailet.MailAddress; +import org.xbill.DNS.Lookup; +import org.xbill.DNS.MXRecord; +import org.xbill.DNS.Record; +import org.xbill.DNS.TextParseException; +import org.xbill.DNS.Type; + +/** + *

This thread

+ * + * Heavily leverages the RemoteDelivery class from James + */ +public class RemoteDelivery extends Thread implements ConfigurationChangeListener { + + private boolean running = false; + private Session mailSession = null; + private ObjectPool myObjectPool = null; + + private static final String MAIL_MIME_CHARSET = "mail.mime.charset"; + private static final String MAIL_SMTP_CONNECTIONTIMEOUT = "mail.smtp.connectiontimeout"; + private static final String MAIL_SMTP_HOST = "mail.smtp.host"; + private static final String MAIL_SMTP_LOCALHOST = "mail.smtp.localhost"; + private static final String MAIL_SMTP_TIMEOUT = "mail.smtp.timeout"; + + static private Log log = Configuration.getInstance().getLog(); + + protected QuedItem qi; + protected MailQue que; + + private static final String SMTPScheme = "smtp://"; + + // TODO This is a temporary constructor, it should be changed + public RemoteDelivery(ThreadGroup parentThreadGroup) { + super(parentThreadGroup, RemoteDelivery.class.getSimpleName()); + + // Set up default session + Properties mailSessionProps = System.getProperties(); + mailSessionProps.put(MAIL_SMTP_HOST, Configuration.getInstance().getHostname()); //The SMTP server to connect to. + mailSessionProps.put(MAIL_SMTP_LOCALHOST, Configuration.getInstance().getHostname()); //Local host name. Defaults to InetAddress.getLocalHost().getHostName(). Should not normally need to be set if your JDK and your name service are configured properly. + mailSessionProps.put(MAIL_MIME_CHARSET, Configuration.getInstance().getEncoding()); //The mail.mime.charset System property can be used to specify the default MIME charset to use for encoded words and text parts that don't otherwise specify a charset. Normally, the default MIME charset is derived from the default Java charset, as specified in the file.encoding System property. Most applications will have no need to explicitly set the default MIME charset. In cases where the default MIME charset to be used for mail messages is different than the charset used for files stored on the system, this property should be set. + mailSessionProps.put(MAIL_SMTP_CONNECTIONTIMEOUT, Configuration.getInstance().getDeliveryTimeout()); //Socket connection timeout value in milliseconds. Default is infinite timeout. + mailSessionProps.put(MAIL_SMTP_TIMEOUT, Configuration.getInstance().getDeliveryTimeout()); //Socket I/O timeout value in milliseconds. Default is infinite timeout. + mailSession = Session.getInstance(mailSessionProps); + // Set communication debug + if( log.isDebugEnabled() && Configuration.getInstance().isDeliveryDebug() ) + mailSession.setDebug(true); + } + + + /** + * @deprecated + * @param que + * @param qi + */ + public RemoteDelivery(MailQue que, QuedItem qi) { + this.que = que; + this.qi = qi; + } + + /** + * We can assume that the recipients of this message are all going to the + * same mail server. We will now rely on the JNDI to do DNS MX record lookup + * and try to deliver to the multiple mail servers. If it fails, it should + * throw an exception. + * + * Creation date: (2/24/00 11:25:00 PM) + * + * @param mail + * org.apache.james.core.MailImpl + * @param session + * javax.mail.Session + * @return boolean Whether the delivery was successful and the message can + * be deleted + */ + private boolean deliver(QuedItem qi, Session session) { + MailAddress rcpt = null; + try + { + if( log.isDebugEnabled() ) + log.debug(getClass().getSimpleName()+" ("+getName()+").deliver(): Starting mail delivery. qi="+qi); + + // Get objects required from QuedItem + MailImpl mail = (MailImpl) qi.getMail(); + MimeMessage message = mail.getMessage(); + // Get all recipients + Collection recipients = mail.getRecipients(); +// InternetAddress addr[] = new InternetAddress[recipients.size()]; +// int j = 0; +// // funky ass look because you can't getElementAt() in a Collection +// +// for (Iterator i = recipients.iterator(); i.hasNext(); j++) { +// MailAddress currentRcpt = (MailAddress) i.next(); +// addr[j] = currentRcpt.toInternetAddress(); +// } + if( recipients.size() <= 0 ) + { + if (log.isDebugEnabled()) + log.debug(getClass().getSimpleName()+" ("+getName()+").deliver(): No recipients specified... returning"); + return true; + } + Iterator it = recipients.iterator(); + while (it.hasNext()) { + rcpt = (MailAddress) it.next(); + if( !qi.recepientHasBeenHandled(rcpt) ) + break; + } + InternetAddress[] addr = new InternetAddress[]{rcpt.toInternetAddress()}; + + // If recipient is null, we could not handle this email + if (rcpt == null) + { + log.error(getClass().getSimpleName()+" ("+getName()+").deliver(): Could not find unhandled recipient."); + return false; + } + String host = rcpt.getHost(); + // Lookup the possible targets + // Figure out which servers to try to send to. This collection + // will hold all the possible target servers + Collection targetServers = null; + // theoretically it is possible to not hav eone that hasn't been + // handled + // however that's only if something has gone really wrong. + try { + // targetServers = MXLookup.urlsForHost(host); // farking + // unreliable jndi bs + targetServers = getMXRecordsForHost(host); + } catch (Exception e) { + log.error(getClass().getSimpleName()+" ("+getName()+" ).deliver(): Could not get MX for "+host+".",e); + } + if (targetServers == null || targetServers.size() == 0) { + log.warn(getClass().getSimpleName()+" ("+getName()+").deliver(): No mail server found for: " + host); + StringBuffer exceptionBuffer = new StringBuffer(128) + .append( + "I found no MX record entries for the hostname ") + .append(host) + .append( + ". I cannot determine where to send this message."); + return failMessage(qi, rcpt, new MessagingException( + exceptionBuffer.toString()), true); + } else if (log.isTraceEnabled()) { + log.trace(getClass().getSimpleName()+" ("+getName()+").deliver(): "+ targetServers.size() + " servers found for "+ host+"."); + } + MessagingException lastError = null; + Iterator i = targetServers.iterator(); + while (i.hasNext()) { + try { + URLName outgoingMailServer = (URLName) i.next(); + StringBuffer logMessageBuffer = null; + if( log.isDebugEnabled() ) + { + logMessageBuffer = new StringBuffer(256) + .append(getClass().getSimpleName()) + .append(" (") + .append(getName()) + .append(").deliver(): ") + .append("Attempting delivery of ") + .append(mail.getName()) + .append(" to host ") + .append(outgoingMailServer.toString()) + .append(" to addresses ") + .append(Arrays.asList(addr)); + log.debug(logMessageBuffer.toString()); + } + Properties props = session.getProperties(); + if (mail.getSender() == null) { + props.put("mail.smtp.from", "<>"); + } else { + String sender = mail.getSender().toString(); + props.put("mail.smtp.from", sender); + } + // Many of these properties are only in later JavaMail + // versions + // "mail.smtp.ehlo" //default true + // "mail.smtp.auth" //default false + // "mail.smtp.dsn.ret" //default to nothing... appended + // as + // RET= after MAIL FROM line. + // "mail.smtp.dsn.notify" //default to + // nothing...appended as + // NOTIFY= after RCPT TO line. + Transport transport = null; + try { + transport = session.getTransport(outgoingMailServer); + try { + transport.connect(); + } catch (MessagingException me) { + log.error(getClass().getSimpleName()+" ("+getName()+").deliver(): Connection failed.",me); + // Any error on connect should cause the mailet + // to + // attempt + // to connect to the next SMTP server associated + // with this MX record, + // assuming the number of retries hasn't been + // exceeded. + if (failMessage(qi, rcpt, me, false)) { + return true; + } else { + continue; + } + } + transport.sendMessage(message, addr); + // log.debug("message sent to " +addr); + /*TODO: catch failures that should result + * in failure with no retries + } catch (SendFailedException sfe){ + qi.failForRecipient(que, ); + */ + } finally { + if (transport != null) { + transport.close(); + transport = null; + } + } + logMessageBuffer = new StringBuffer(256) + .append("Mail (") + .append(mail.getName()) + .append(") sent successfully to ") + .append(outgoingMailServer); + log.debug(getClass().getSimpleName()+" ("+getName()+").deliver(): "+logMessageBuffer.toString()); + qi.succeededForRecipient(que, rcpt); + return true; + } catch (MessagingException me) { + log.error(getClass().getSimpleName()+" ("+getName()+").deliver(): ", me); + // MessagingException are horribly difficult to figure + // out + // what actually happened. + StringBuffer exceptionBuffer = new StringBuffer(256) + .append("Exception delivering message (") + .append(mail.getName()) + .append(") - ") + .append(me.getMessage()); + log.warn(exceptionBuffer.toString()); + if ((me.getNextException() != null) + && (me.getNextException() instanceof java.io.IOException)) { + // This is more than likely a temporary failure + // If it's an IO exception with no nested exception, + // it's probably + // some socket or weird I/O related problem. + lastError = me; + continue; + } + // This was not a connection or I/O error particular to + // one + // SMTP server of an MX set. Instead, it is almost + // certainly + // a protocol level error. In this case we assume that + // this + // is an error we'd encounter with any of the SMTP + // servers + // associated with this MX record, and we pass the + // exception + // to the code in the outer block that determines its + // severity. + throw me; + } // end catch + } // end while + // If we encountered an exception while looping through, + // throw the last MessagingException we caught. We only + // do this if we were unable to send the message to any + // server. If sending eventually succeeded, we exit + // deliver() though the return at the end of the try + // block. + if (lastError != null) { + throw lastError; + } +// } // END if (rcpt != null) +// else { +// log +// .error("unable to find recipient that handn't already been handled"); +// } + } catch (SendFailedException sfe) { + log.error(getClass().getSimpleName()+" ("+getName()+").deliver(): ",sfe); + boolean deleteMessage = false; + Collection recipients = qi.getMail().getRecipients(); + // Would like to log all the types of email addresses + if (log.isTraceEnabled()) { + log.trace(getClass().getSimpleName()+" ("+getName()+").deliver(): Recipients: " + recipients); + } + /* + * The rest of the recipients failed for one reason or another. + * + * SendFailedException actually handles this for us. For example, if + * you send a message that has multiple invalid addresses, you'll + * get a top-level SendFailedException that that has the valid, + * valid-unsent, and invalid address lists, with all of the server + * response messages will be contained within the nested exceptions. + * [Note: the content of the nested exceptions is implementation + * dependent.] + * + * sfe.getInvalidAddresses() should be considered permanent. + * sfe.getValidUnsentAddresses() should be considered temporary. + * + * JavaMail v1.3 properly populates those collections based upon the + * 4xx and 5xx response codes. + * + */ + if (sfe.getInvalidAddresses() != null) { + Address[] address = sfe.getInvalidAddresses(); + if (address.length > 0) { + /* + * This clear() call modify the original recipient object. + * After this clear the mail recipient cout is changed, and + * the isCompleted() method of QuedItem gives back wrong + * result, because it get not the original count of + * recipients. So I comment this clearing and replace + * collection with a new one. + * + * TODO We need this part? + */ +// recipients.clear(); + Collection invalidRecipients = new HashSet(); + for (int i = 0; i < address.length; i++) { + try { + invalidRecipients.add(new MailAddress(address[i] + .toString())); + } catch (ParseException pe) { + // this should never happen ... we should have + // caught malformed addresses long before we + // got to this code. + if (log.isDebugEnabled()) { + log.debug(getClass().getSimpleName()+" ("+getName()+").deliver(): Can't parse invalid address: " + + pe.getMessage()); + } + } + } + if (log.isDebugEnabled()) { + log.debug(getClass().getSimpleName()+" ("+getName()+").deliver(): Invalid recipients: " + invalidRecipients); + } + deleteMessage = failMessage(qi, rcpt, sfe, true); + } + } + if (sfe.getValidUnsentAddresses() != null) { + Address[] address = sfe.getValidUnsentAddresses(); + if (address.length > 0) { + /* + * This clear() call modify the original recipient object. + * After this clear the mail recipient cout is changed, and + * the isCompleted() method of QuedItem gives back wrong + * result, because it get not the original count of + * recipients. So I comment this clearing and replace + * collection with a new one. + * + * TODO We need this part? + */ +// recipients.clear(); + Collection validUnsentRecipients = new HashSet(); + for (int i = 0; i < address.length; i++) { + try { + validUnsentRecipients.add(new MailAddress(address[i] + .toString())); + } catch (ParseException pe) { + // this should never happen ... we should have + // caught malformed addresses long before we + // got to this code. + log.error(getClass().getSimpleName()+" ("+getName()+").deliver(): Can't parse unsent address.", pe); + } + } + if (log.isDebugEnabled()) { + log.debug(getClass().getSimpleName()+" ("+getName()+").deliver(): Unsent recipients: " + validUnsentRecipients); + } + deleteMessage = failMessage(qi, rcpt, sfe, false); + } + } + return deleteMessage; + } catch (MessagingException ex) { + log.error(getClass().getSimpleName()+" ("+getName()+").deliver(): ",ex); + // We should do a better job checking this... if the failure is a + // general + // connect exception, this is less descriptive than more specific + // SMTP command + // failure... have to lookup and see what are the various Exception + // possibilities + // Unable to deliver message after numerous tries... fail + // accordingly + // We check whether this is a 5xx error message, which + // indicates a permanent failure (like account doesn't exist + // or mailbox is full or domain is setup wrong). + // We fail permanently if this was a 5xx error + return failMessage(qi, rcpt, ex, ('5' == ex.getMessage().charAt(0))); + } catch (Throwable t) { + log.error(getClass().getSimpleName()+" ("+getName()+").deliver():",t); + } + /* + * If we get here, we've exhausted the loop of servers without sending + * the message or throwing an exception. One case where this might + * happen is if we get a MessagingException on each transport.connect(), + * e.g., if there is only one server and we get a connect exception. + * Return FALSE to keep run() from deleting the message. + */ + return false; + } + + /** + * Insert the method's description here. Creation date: (2/25/00 1:14:18 AM) + * + * @param mail + * org.apache.james.core.MailImpl + * @param exception + * java.lang.Exception + * @param boolean + * permanent + * @return boolean Whether the message failed fully and can be deleted + */ + private boolean failMessage(QuedItem qi, MailAddress recepient, + MessagingException ex, boolean permanent) { + log.debug(getClass().getSimpleName()+" ("+getName()+").failMessage(): Method called. qi="+qi); + // weird printy bits inherited from JAMES + MailImpl mail = (MailImpl) qi.getMail(); + StringWriter sout = new StringWriter(); + PrintWriter out = new PrintWriter(sout, true); + if (permanent) { + out.print("Permanent"); + } else { + out.print("Temporary"); + } + StringBuffer logBuffer = new StringBuffer(64) + .append(getClass().getSimpleName()) + .append(" (") + .append(getName()) + .append(").failMessage(): ") + .append( + " exception delivering mail (").append(mail.getName()).append( + ": "); + out.print(logBuffer.toString()); + ex.printStackTrace(out); + if (log.isWarnEnabled()) { + log.warn(sout.toString()); + } + // ////////////// + // / It is important to note that deliver will pass us a mail with a + // modified + // / list of recepients non permanent ones will only have valid + // recepients left + // / + if (!permanent) { + if (!mail.getState().equals(Mail.ERROR)) { + mail.setState(Mail.ERROR); + mail.setErrorMessage("0"); + mail.setLastUpdated(new Date()); + } + if (qi.retryable(recepient)) { + if (log.isDebugEnabled()) { + logBuffer = new StringBuffer(128) + .append(getClass().getSimpleName()+" ("+getName()+").failMessage(): ") + .append("Storing message ") + .append(mail.getName()) + .append(" into que after ") +// .append(qi.getNumAttempts()) + .append(" attempts") + ; + log.debug(logBuffer.toString()); + } + qi.retry(que, recepient); + //mail.setErrorMessage(qi.getNumAttempts() + ""); + mail.setLastUpdated(new Date()); + return false; + } else { + if (log.isDebugEnabled()) { + logBuffer = new StringBuffer(128) + .append(getClass().getSimpleName()+" ("+getName()+").failMessage(): ") + .append("Bouncing message ") + .append(mail.getName()) + .append(" after ") +// .append(qi.getNumAttempts()) + .append(" attempts") + ; + log.debug(logBuffer.toString()); + } + qi.failForRecipient(que, recepient, ex); + } + } else { + qi.failForRecipient(que, recepient, ex); + } + try + { + Bouncer.bounce(que, mail, ex.toString(), Configuration.getInstance().getPostmaster()); + }catch (MessagingException me) + { + log.error(getClass().getSimpleName()+" ("+getName()+").failMessage(): failed to bounce",me); + } + return true; + } + + @Override + public void run() { + running = true; + + while( running ) + { + // Try to deliver the QuedItem + try + { + if( qi != null ) + { + log.trace(getClass().getSimpleName()+" ("+getName()+").run(): Call delivering... qi="+qi); + deliver(qi, mailSession); + } + }catch (Exception e) + { + log.error(getClass().getSimpleName()+" ("+getName()+").run(): Could not deliver message. qi="+qi, e); + }finally + /* + * Sometimes it could be a QuedItem is in the qi variable with + * IN_PROCESS status. This QuedItem have to be released before we + * finish this round of running. After releasing the qi variable + * will be nullified. + */ + { + if( qi != null && !qi.isReadyToSend() ) + { + qi.release(); + log.trace(getClass().getSimpleName()+" ("+getName()+").run(): Release item. qi="+qi); + qi = null; + } + } + synchronized (this) { + if( qi == null ) + { + try + { + log.info(getClass().getSimpleName()+" ("+getName()+").run(): Try to give back RemoteDelivery object into the pool."); + myObjectPool.returnObject(this); + }catch (Exception e) + { + log.error(getClass().getSimpleName()+" ("+getName()+").run(): The object could not be returned into the pool.",e); + this.shutdown(); + } + // Wait for next QuedItem to deliver + try + { + if( running ) + { + log.trace(getClass().getSimpleName()+" ("+getName()+").run(): Wait for next sendable item."); + wait(); + } + } catch (InterruptedException ie) + /* + * On interrupt we shutdown this thread and remove from + * pool. It could be a QuedItem in the qi variable, so we + * try to release it before finish the work. + */ + { + if( qi != null ) + { + log.trace(getClass().getSimpleName()+" ("+getName()+").run(): Release item after interruption. qi="+qi); + qi.release(); + qi = null; + } + running = false; + try + { + log.info(getClass().getSimpleName()+" ("+getName()+").run(): Invalidate RemoteDelivery object in the pool."); + myObjectPool.invalidateObject(this); + }catch (Exception e) + { + throw new RuntimeException("The object could not be invalidated in the pool.",e); + } + } + } + } + } + } + + /** + *

You can set the next QuedItem to deliver with this method. It wakes + * up this delivery thread which try to deliver the QuedItem set.

+ * + * @param qi A QuedItem to deliver. + * @throws MessagingException This is thrown if the previous qi is not + * null. + */ + public void setQuedItem(QuedItem qi) throws MessagingException { + /* + * If the this.qi variable is not null, then the previous item could be + * in. If the previous item is not ready to send and is not completed, + * we have to try send this item with this thread. After wake up this + * thread we throw an Exception. + */ + synchronized (this) { + if( this.qi != null ) + { + if( !this.qi.isReadyToSend() && !this.qi.isCompleted() ) + notify(); + throw new MessagingException("The previous QuedItem was not removed from this thread."); + } + this.qi = qi; + log.trace(getClass().getSimpleName()+" ("+getName()+").setQuedItem(): Item was set. qi="+qi); + notify(); + } + } + + /** + *

This method sets the parent pool, which this thread is given back + * into after finishing delivery.

+ * + * @param pool The pool which this thread is borrowed from. + */ + public void setParentPool(ObjectPool pool) { + this.myObjectPool = pool; + } + + public void setQue(MailQue que) { + this.que = que; + } + + /** + *

This method gives back the host name(s) where we can send the email. + *

+ * + *

First time we ask DNS to find MX record(s) of a domain name. If no MX + * records are found, we check the upper level domains (if exists). At last + * we try to get the domain A record, because the MX server could be same as + * the normal domain handler server. If only upper level domain has MX + * record then we append the A record of original hostname (if exists) as + * first element of record collection. If none of these tries are + * successful, we give back an empty collection.

+ * + * Special Thanks to Tim Motika (tmotika at ionami dot com) for + * his reworking of this method. + * + * @param hostName We search the associated MX server of this hostname. + * @return Collection of URLName objects. If no MX server found, then it + * gives back an empty collection. + * + * TODO public -> private + * + */ + public Collection getMXRecordsForHost(String hostName) { + + Vector recordsColl = null; + try { + boolean foundOriginalMX = true; + Record[] records = new Lookup(hostName, Type.MX).run(); + + /* + * Sometimes we should send an email to a subdomain which does not + * have own MX record and MX server. At this point we should find an + * upper level domain and server where we can deliver our email. + * + * Example: subA.subB.domain.name has not own MX record and + * subB.domain.name is the mail exchange master of the subA domain + * too. + */ + if( records == null || records.length == 0 ) + { + foundOriginalMX = false; + String upperLevelHostName = hostName; + while( records == null && + upperLevelHostName.indexOf(".") != upperLevelHostName.lastIndexOf(".") && + upperLevelHostName.lastIndexOf(".") != -1 + ) + { + upperLevelHostName = upperLevelHostName.substring(upperLevelHostName.indexOf(".")+1); + records = new Lookup(upperLevelHostName, Type.MX).run(); + } + } + + if( records != null ) + { + // Sort in MX priority (higher number is lower priority) + Arrays.sort(records, new Comparator() { + @Override + public int compare(Record arg0, Record arg1) { + return ((MXRecord)arg0).getPriority()-((MXRecord)arg1).getPriority(); + } + }); + // Create records collection + recordsColl = new Vector(records.length); + for (int i = 0; i < records.length; i++) + { + MXRecord mx = (MXRecord) records[i]; + String targetString = mx.getTarget().toString(); + URLName uName = new URLName( + RemoteDelivery.SMTPScheme + + targetString.substring(0, targetString.length() - 1) + ); + recordsColl.add(uName); + } + }else + { + foundOriginalMX = false; + recordsColl = new Vector(); + } + + /* + * If we found no MX record for the original hostname (the upper + * level domains does not matter), then we add the original domain + * name (identified with an A record) to the record collection, + * because the mail exchange server could be the main server too. + * + * We append the A record to the first place of the record + * collection, because the standard says if no MX record found then + * we should to try send email to the server identified by the A + * record. + */ + if( !foundOriginalMX ) + { + Record[] recordsTypeA = new Lookup(hostName, Type.A).run(); + if (recordsTypeA != null && recordsTypeA.length > 0) + { + recordsColl.add(0, new URLName(RemoteDelivery.SMTPScheme + hostName)); + } + } + + } catch (TextParseException e) { + log.warn(getClass().getSimpleName()+" ("+getName()+").getMXRecordsForHost(): Failed get MX record.",e); + } + + return recordsColl; + } + + public void shutdown() { + log.trace(getClass().getSimpleName()+" ("+getName()+").shutdown(): Called."); + running = false; + synchronized (this) { + notify(); + } + } + + + @Override + public void configChanged(String parameterName) { + if( ConfigurationMBean.PARAM_DELIVERY_TIMEOUT.equals(parameterName) ) + { + Properties sessProps = mailSession.getProperties(); + sessProps.setProperty(MAIL_SMTP_CONNECTIONTIMEOUT, String.valueOf(Configuration.getInstance().getDeliveryTimeout())); + sessProps.setProperty(MAIL_SMTP_TIMEOUT, String.valueOf(Configuration.getInstance().getDeliveryTimeout())); + }else + if( ConfigurationMBean.PARAM_ENCODING.equals(parameterName) ) + { + Properties sessProps = mailSession.getProperties(); + sessProps.setProperty(MAIL_MIME_CHARSET, Configuration.getInstance().getEncoding()); + }else + if( ConfigurationMBean.PARAM_HOSTNAME.equals(parameterName) ) + { + Properties sessProps = mailSession.getProperties(); + sessProps.setProperty(MAIL_SMTP_HOST, Configuration.getInstance().getHostname()); + sessProps.setProperty(MAIL_SMTP_LOCALHOST, Configuration.getInstance().getHostname()); + }else + if( ConfigurationMBean.PARAM_DELIVERY_DEBUG.equals(parameterName) ) + { + mailSession.setDebug( + log.isDebugEnabled() && + Configuration.getInstance().isDeliveryDebug() + ); + } + } + +} Index: 3rdParty_sources/aspirin/org/masukomi/aspirin/core/SimpleMailWatcherImpl.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/masukomi/aspirin/core/SimpleMailWatcherImpl.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/masukomi/aspirin/core/SimpleMailWatcherImpl.java 17 Aug 2012 14:15:37 -0000 1.1 @@ -0,0 +1,109 @@ +/* + * Created on May 6, 2004 + * + * + */ +package org.masukomi.aspirin.core; + +import javax.mail.MessagingException; +import javax.mail.internet.MimeMessage; + +import org.apache.commons.logging.Log; +import org.apache.mailet.MailAddress; +/** + * @author masukomi + * + * This class is provided mainly as an example. It will notify you when *a* message succeeds + * or fails but doesn't take the recipients into account and it doesn't care *what* message has + * succeeded or failed. It is extremely simplistic and should not be used as a guage of what a + * sophisticated MailWatcher is capable of. + */ +public class SimpleMailWatcherImpl implements MailWatcher { + static private Log log = Configuration.getInstance().getLog(); + boolean hasSucceeded = false; + boolean hasFailed = false; + MimeMessage message; + /** a collection of import org.apache.mailet.MailAddress objects relating to the e-mail */ +// Collection recipients; + MailAddress lastRecipient; + /** + * + */ + public SimpleMailWatcherImpl() { + super(); + // TODO Auto-generated constructor stub + } + public SimpleMailWatcherImpl(MimeMessage message) { + super(); + this.message = message; + // TODO Auto-generated constructor stub + } + + /** + * Warning: this method may take a long time to return while a message is sending. + * @return true if the delivery succeeds + * + */ + public boolean blockingSuccessCheck(){ + while(hasFailed == false && hasSucceeded == false){ + try { + Thread.sleep(1000); + } catch (InterruptedException e1) { + // TODO Auto-generated catch block + log.error(e1); + } + } + return hasSucceeded; + } + + public void resetTestValues(){ + hasSucceeded=false; + hasFailed=false; + } + /** + * @return Returns the message. + */ + public MimeMessage getMessage() { + return message; + } +// /** +// * @return Returns the recipients. +// */ +// public Collection getRecipients() { +// return recipients; +// } + /* (non-Javadoc) + * @see org.masukomi.aspirin.core.MailWatcher#deliverySuccess(javax.mail.internet.MimeMessage, org.apache.mailet.MailAddress) + */ + public void deliverySuccess(MailQue que, MimeMessage message, MailAddress recipient) { + if (this.message == null){ + hasSucceeded = true; + lastRecipient = recipient; + que.removeWatcher(this); + } else if (this.message == message) { + hasSucceeded = true; + lastRecipient = recipient; + que.removeWatcher(this); + } + + } + /* (non-Javadoc) + * @see org.masukomi.aspirin.core.MailWatcher#deliveryFailure(javax.mail.internet.MimeMessage, org.apache.mailet.MailAddress) + */ + public void deliveryFailure(MailQue que, MimeMessage message, MailAddress recipient, MessagingException mex) { + if (this.message == null){ + hasFailed = true; + lastRecipient = recipient; + que.removeWatcher(this); + } else if (this.message == message) { + hasFailed = true; + lastRecipient = recipient; + que.removeWatcher(this); + } + } + @Override + public void deliveryFinished(MailQue que, MimeMessage message) { + // TODO Auto-generated method stub + + } +} Index: 3rdParty_sources/aspirin/org/masukomi/aspirin/core/SimpleMimeMessageGenerator.java =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/aspirin/org/masukomi/aspirin/core/SimpleMimeMessageGenerator.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/aspirin/org/masukomi/aspirin/core/SimpleMimeMessageGenerator.java 17 Aug 2012 14:15:38 -0000 1.1 @@ -0,0 +1,27 @@ +/* + * Created on Jun 17, 2004 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Generation - Code and Comments + */ +package org.masukomi.aspirin.core; + +import java.util.Properties; + +import javax.mail.Session; +import javax.mail.internet.MimeMessage; + +/** + * @author masukomi + * + * A simple convenience class that generates a MimeMessage for you to fill in + * without you having to remember / worry about Sessions or Properties or any of that. + * No properties are set in the creation of this MimeMessage. + */ +public class SimpleMimeMessageGenerator { + + static public MimeMessage getNewMimeMessage(){ + return new MimeMessage(Session.getDefaultInstance(new Properties())); + } + +} Index: 3rdParty_sources/ckeditor/adapters/jquery.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/adapters/jquery.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/adapters/jquery.js 17 Aug 2012 14:15:47 -0000 1.1 @@ -0,0 +1,306 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * @fileOverview jQuery adapter provides easy use of basic CKEditor functions + * and access to internal API. It also integrates some aspects of CKEditor with + * jQuery framework. + * + * Every TEXTAREA, DIV and P elements can be converted to working editor. + * + * Plugin exposes some of editor's event to jQuery event system. All of those are namespaces inside + * ".ckeditor" namespace and can be binded/listened on supported textarea, div and p nodes. + * + * Available jQuery events: + * - instanceReady.ckeditor( editor, rootNode ) + * Triggered when new instance is ready. + * - destroy.ckeditor( editor ) + * Triggered when instance is destroyed. + * - getData.ckeditor( editor, eventData ) + * Triggered when getData event is fired inside editor. It can change returned data using eventData reference. + * - setData.ckeditor( editor ) + * Triggered when getData event is fired inside editor. + * + * @example + * + * + * + */ + +(function() +{ + /** + * Allows CKEditor to override jQuery.fn.val(), making it possible to use the val() + * function on textareas, as usual, having it synchronized with CKEditor.
+ *
+ * This configuration option is global and executed during the jQuery Adapter loading. + * It can't be customized across editor instances. + * @type Boolean + * @example + * <script> + * CKEDITOR.config.jqueryOverrideVal = true; + * </script> + * <!-- Important: The JQuery adapter is loaded *after* setting jqueryOverrideVal --> + * <script src="/ckeditor/adapters/jquery.js"></script> + * @example + * // ... then later in the code ... + * + * $( 'textarea' ).ckeditor(); + * // ... + * $( 'textarea' ).val( 'New content' ); + */ + CKEDITOR.config.jqueryOverrideVal = typeof CKEDITOR.config.jqueryOverrideVal == 'undefined' + ? true : CKEDITOR.config.jqueryOverrideVal; + + var jQuery = window.jQuery; + + if ( typeof jQuery == 'undefined' ) + return; + + // jQuery object methods. + jQuery.extend( jQuery.fn, + /** @lends jQuery.fn */ + { + /** + * Return existing CKEditor instance for first matched element. + * Allows to easily use internal API. Doesn't return jQuery object. + * + * Raised exception if editor doesn't exist or isn't ready yet. + * + * @name jQuery.ckeditorGet + * @return CKEDITOR.editor + * @see CKEDITOR.editor + */ + ckeditorGet: function() + { + var instance = this.eq( 0 ).data( 'ckeditorInstance' ); + if ( !instance ) + throw "CKEditor not yet initialized, use ckeditor() with callback."; + return instance; + }, + /** + * Triggers creation of CKEditor in all matched elements (reduced to DIV, P and TEXTAREAs). + * Binds callback to instanceReady event of all instances. If editor is already created, than + * callback is fired right away. + * + * Mixed parameter order allowed. + * + * @param callback Function to be run on editor instance. Passed parameters: [ textarea ]. + * Callback is fiered in "this" scope being ckeditor instance and having source textarea as first param. + * + * @param config Configuration options for new instance(s) if not already created. + * See URL + * + * @example + * $( 'textarea' ).ckeditor( function( textarea ) { + * $( textarea ).val( this.getData() ) + * } ); + * + * @name jQuery.fn.ckeditor + * @return jQuery.fn + */ + ckeditor: function( callback, config ) + { + if ( !CKEDITOR.env.isCompatible ) + return this; + + if ( !jQuery.isFunction( callback )) + { + var tmp = config; + config = callback; + callback = tmp; + } + config = config || {}; + + this.filter( 'textarea, div, p' ).each( function() + { + var $element = jQuery( this ), + editor = $element.data( 'ckeditorInstance' ), + instanceLock = $element.data( '_ckeditorInstanceLock' ), + element = this; + + if ( editor && !instanceLock ) + { + if ( callback ) + callback.apply( editor, [ this ] ); + } + else if ( !instanceLock ) + { + // CREATE NEW INSTANCE + + // Handle config.autoUpdateElement inside this plugin if desired. + if ( config.autoUpdateElement + || ( typeof config.autoUpdateElement == 'undefined' && CKEDITOR.config.autoUpdateElement ) ) + { + config.autoUpdateElementJquery = true; + } + + // Always disable config.autoUpdateElement. + config.autoUpdateElement = false; + $element.data( '_ckeditorInstanceLock', true ); + + // Set instance reference in element's data. + editor = CKEDITOR.replace( element, config ); + $element.data( 'ckeditorInstance', editor ); + + // Register callback. + editor.on( 'instanceReady', function( event ) + { + var editor = event.editor; + setTimeout( function() + { + // Delay bit more if editor is still not ready. + if ( !editor.element ) + { + setTimeout( arguments.callee, 100 ); + return; + } + + // Remove this listener. + event.removeListener( 'instanceReady', this.callee ); + + // Forward setData on dataReady. + editor.on( 'dataReady', function() + { + $element.trigger( 'setData' + '.ckeditor', [ editor ] ); + }); + + // Forward getData. + editor.on( 'getData', function( event ) { + $element.trigger( 'getData' + '.ckeditor', [ editor, event.data ] ); + }, 999 ); + + // Forward destroy event. + editor.on( 'destroy', function() + { + $element.trigger( 'destroy.ckeditor', [ editor ] ); + }); + + // Integrate with form submit. + if ( editor.config.autoUpdateElementJquery && $element.is( 'textarea' ) && $element.parents( 'form' ).length ) + { + var onSubmit = function() + { + $element.ckeditor( function() + { + editor.updateElement(); + }); + }; + + // Bind to submit event. + $element.parents( 'form' ).submit( onSubmit ); + + // Bind to form-pre-serialize from jQuery Forms plugin. + $element.parents( 'form' ).bind( 'form-pre-serialize', onSubmit ); + + // Unbind when editor destroyed. + $element.bind( 'destroy.ckeditor', function() + { + $element.parents( 'form' ).unbind( 'submit', onSubmit ); + $element.parents( 'form' ).unbind( 'form-pre-serialize', onSubmit ); + }); + } + + // Garbage collect on destroy. + editor.on( 'destroy', function() + { + $element.data( 'ckeditorInstance', null ); + }); + + // Remove lock. + $element.data( '_ckeditorInstanceLock', null ); + + // Fire instanceReady event. + $element.trigger( 'instanceReady.ckeditor', [ editor ] ); + + // Run given (first) code. + if ( callback ) + callback.apply( editor, [ element ] ); + }, 0 ); + }, null, null, 9999); + } + else + { + // Editor is already during creation process, bind our code to the event. + CKEDITOR.on( 'instanceReady', function( event ) + { + var editor = event.editor; + setTimeout( function() + { + // Delay bit more if editor is still not ready. + if ( !editor.element ) + { + setTimeout( arguments.callee, 100 ); + return; + } + + if ( editor.element.$ == element ) + { + // Run given code. + if ( callback ) + callback.apply( editor, [ element ] ); + } + }, 0 ); + }, null, null, 9999); + } + }); + return this; + } + }); + + // New val() method for objects. + if ( CKEDITOR.config.jqueryOverrideVal ) + { + jQuery.fn.val = CKEDITOR.tools.override( jQuery.fn.val, function( oldValMethod ) + { + /** + * CKEditor-aware val() method. + * + * Acts same as original jQuery val(), but for textareas which have CKEditor instances binded to them, method + * returns editor's content. It also works for settings values. + * + * @param oldValMethod + * @name jQuery.fn.val + */ + return function( newValue, forceNative ) + { + var isSetter = typeof newValue != 'undefined', + result; + + this.each( function() + { + var $this = jQuery( this ), + editor = $this.data( 'ckeditorInstance' ); + + if ( !forceNative && $this.is( 'textarea' ) && editor ) + { + if ( isSetter ) + editor.setData( newValue ); + else + { + result = editor.getData(); + // break; + return null; + } + } + else + { + if ( isSetter ) + oldValMethod.call( $this, newValue ); + else + { + result = oldValMethod.call( $this ); + // break; + return null; + } + } + + return true; + }); + return isSetter ? this : result; + }; + }); + } +})(); Index: 3rdParty_sources/ckeditor/core/_bootstrap.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/core/_bootstrap.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/core/_bootstrap.js 17 Aug 2012 14:15:40 -0000 1.1 @@ -0,0 +1,87 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * @fileOverview API initialization code. + */ + +(function() +{ + // Disable HC detaction in WebKit. (#5429) + if ( CKEDITOR.env.webkit ) + { + CKEDITOR.env.hc = false; + return; + } + + // Check whether high contrast is active by creating a colored border. + var hcDetect = CKEDITOR.dom.element.createFromHtml( + '
', CKEDITOR.document ); + + hcDetect.appendTo( CKEDITOR.document.getHead() ); + + // Update CKEDITOR.env. + // Catch exception needed sometimes for FF. (#4230) + try + { + CKEDITOR.env.hc = hcDetect.getComputedStyle( 'border-top-color' ) == hcDetect.getComputedStyle( 'border-right-color' ); + } + catch (e) + { + CKEDITOR.env.hc = false; + } + + if ( CKEDITOR.env.hc ) + CKEDITOR.env.cssClass += ' cke_hc'; + + hcDetect.remove(); +})(); + +// Load core plugins. +CKEDITOR.plugins.load( CKEDITOR.config.corePlugins.split( ',' ), function() + { + CKEDITOR.status = 'loaded'; + CKEDITOR.fire( 'loaded' ); + + // Process all instances created by the "basic" implementation. + var pending = CKEDITOR._.pending; + if ( pending ) + { + delete CKEDITOR._.pending; + + for ( var i = 0 ; i < pending.length ; i++ ) + CKEDITOR.add( pending[ i ] ); + } + }); + +// Needed for IE6 to not request image (HTTP 200 or 304) for every CSS background. (#6187) +if ( CKEDITOR.env.ie ) +{ + // Remove IE mouse flickering on IE6 because of background images. + try + { + document.execCommand( 'BackgroundImageCache', false, true ); + } + catch (e) + { + // We have been reported about loading problems caused by the above + // line. For safety, let's just ignore errors. + } +} + +/** + * Indicates that CKEditor is running on a High Contrast environment. + * @name CKEDITOR.env.hc + * @example + * if ( CKEDITOR.env.hc ) + * alert( 'You're running on High Contrast mode. The editor interface will get adapted to provide you a better experience.' ); + */ + +/** + * Fired when a CKEDITOR core object is fully loaded and ready for interaction. + * @name CKEDITOR#loaded + * @event + */ Index: 3rdParty_sources/ckeditor/core/ckeditor.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/core/ckeditor.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/core/ckeditor.js 17 Aug 2012 14:15:40 -0000 1.1 @@ -0,0 +1,141 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * @fileOverview Contains the third and last part of the {@link CKEDITOR} object + * definition. + */ + +// Remove the CKEDITOR.loadFullCore reference defined on ckeditor_basic. +delete CKEDITOR.loadFullCore; + +/** + * Holds references to all editor instances created. The name of the properties + * in this object correspond to instance names, and their values contains the + * {@link CKEDITOR.editor} object representing them. + * @type {Object} + * @example + * alert( CKEDITOR.instances.editor1.name ); // "editor1" + */ +CKEDITOR.instances = {}; + +/** + * The document of the window holding the CKEDITOR object. + * @type {CKEDITOR.dom.document} + * @example + * alert( CKEDITOR.document.getBody().getName() ); // "body" + */ +CKEDITOR.document = new CKEDITOR.dom.document( document ); + +/** + * Adds an editor instance to the global {@link CKEDITOR} object. This function + * is available for internal use mainly. + * @param {CKEDITOR.editor} editor The editor instance to be added. + * @example + */ +CKEDITOR.add = function( editor ) +{ + CKEDITOR.instances[ editor.name ] = editor; + + editor.on( 'focus', function() + { + if ( CKEDITOR.currentInstance != editor ) + { + CKEDITOR.currentInstance = editor; + CKEDITOR.fire( 'currentInstance' ); + } + }); + + editor.on( 'blur', function() + { + if ( CKEDITOR.currentInstance == editor ) + { + CKEDITOR.currentInstance = null; + CKEDITOR.fire( 'currentInstance' ); + } + }); +}; + +/** + * Removes an editor instance from the global {@link CKEDITOR} object. This function + * is available for internal use only. External code must use {@link CKEDITOR.editor.prototype.destroy} + * to avoid memory leaks. + * @param {CKEDITOR.editor} editor The editor instance to be removed. + * @example + */ +CKEDITOR.remove = function( editor ) +{ + delete CKEDITOR.instances[ editor.name ]; +}; + +/** + * Perform global clean up to free as much memory as possible + * when there are no instances left + */ +CKEDITOR.on( 'instanceDestroyed', function () + { + if ( CKEDITOR.tools.isEmpty( this.instances ) ) + CKEDITOR.fire( 'reset' ); + }); + +// Load the bootstrap script. +CKEDITOR.loader.load( 'core/_bootstrap' ); // @Packager.RemoveLine + +// Tri-state constants. + +/** + * Used to indicate the ON or ACTIVE state. + * @constant + * @example + */ +CKEDITOR.TRISTATE_ON = 1; + +/** + * Used to indicate the OFF or NON ACTIVE state. + * @constant + * @example + */ +CKEDITOR.TRISTATE_OFF = 2; + +/** + * Used to indicate DISABLED state. + * @constant + * @example + */ +CKEDITOR.TRISTATE_DISABLED = 0; + +/** + * The editor which is currently active (have user focus). + * @name CKEDITOR.currentInstance + * @type CKEDITOR.editor + * @see CKEDITOR#currentInstance + * @example + * function showCurrentEditorName() + * { + * if ( CKEDITOR.currentInstance ) + * alert( CKEDITOR.currentInstance.name ); + * else + * alert( 'Please focus an editor first.' ); + * } + */ + +/** + * Fired when the CKEDITOR.currentInstance object reference changes. This may + * happen when setting the focus on different editor instances in the page. + * @name CKEDITOR#currentInstance + * @event + * var editor; // Variable to hold a reference to the current editor. + * CKEDITOR.on( 'currentInstance' , function( e ) + * { + * editor = CKEDITOR.currentInstance; + * }); + */ + +/** + * Fired when the last instance has been destroyed. This event is used to perform + * global memory clean up. + * @name CKEDITOR#reset + * @event + */ Index: 3rdParty_sources/ckeditor/core/ckeditor_base.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/core/ckeditor_base.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/core/ckeditor_base.js 17 Aug 2012 14:15:40 -0000 1.1 @@ -0,0 +1,227 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * @fileOverview Contains the first and essential part of the {@link CKEDITOR} + * object definition. + */ + +// #### Compressed Code +// Must be updated on changes in the script as well as updated in the +// ckeditor_source.js and ckeditor_basic_source.js files. + +// if(!window.CKEDITOR)window.CKEDITOR=(function(){var a={timestamp:'',version:'3.6.2',rev:'7275',_:{},status:'unloaded',basePath:(function(){var d=window.CKEDITOR_BASEPATH||'';if(!d){var e=document.getElementsByTagName('script');for(var f=0;f=0?'&':'?')+('t=')+this.timestamp;return d;}},b=window.CKEDITOR_GETURL;if(b){var c=a.getUrl;a.getUrl=function(d){return b.call(a,d)||c.call(a,d);};}return a;})(); + +// #### Raw code +// ATTENTION: read the above "Compressed Code" notes when changing this code. + +/* @Packager.RemoveLine +// Avoid having the editor code initialized twice. (#7588) +// Use CKEDITOR.dom to check whether the full ckeditor.js code has been loaded +// or just ckeditor_basic.js. +// Remove these lines when compressing manually. +if ( window.CKEDITOR && window.CKEDITOR.dom ) + return; +@Packager.RemoveLine */ + +if ( !window.CKEDITOR ) +{ + /** + * @name CKEDITOR + * @namespace This is the API entry point. The entire CKEditor code runs under this object. + * @example + */ + window.CKEDITOR = (function() + { + var CKEDITOR = + /** @lends CKEDITOR */ + { + + /** + * A constant string unique for each release of CKEditor. Its value + * is used, by default, to build the URL for all resources loaded + * by the editor code, guaranteeing clean cache results when + * upgrading. + * @type String + * @example + * alert( CKEDITOR.timestamp ); // e.g. '87dm' + */ + // The production implementation contains a fixed timestamp, unique + // for each release and generated by the releaser. + // (Base 36 value of each component of YYMMDDHH - 4 chars total - e.g. 87bm == 08071122) + timestamp : 'B8DJ5M3', + + /** + * Contains the CKEditor version number. + * @type String + * @example + * alert( CKEDITOR.version ); // e.g. 'CKEditor 3.4.1' + */ + version : '3.6.2', + + /** + * Contains the CKEditor revision number. + * The revision number is incremented automatically, following each + * modification to the CKEditor source code. + * @type String + * @example + * alert( CKEDITOR.revision ); // e.g. '3975' + */ + revision : '7275', + + /** + * Private object used to hold core stuff. It should not be used outside of + * the API code as properties defined here may change at any time + * without notice. + * @private + */ + _ : {}, + + /** + * Indicates the API loading status. The following statuses are available: + *
    + *
  • unloaded: the API is not yet loaded.
  • + *
  • basic_loaded: the basic API features are available.
  • + *
  • basic_ready: the basic API is ready to load the full core code.
  • + *
  • loading: the full API is being loaded.
  • + *
  • loaded: the API can be fully used.
  • + *
+ * @type String + * @example + * if ( CKEDITOR.status == 'loaded' ) + * { + * // The API can now be fully used. + * } + */ + status : 'unloaded', + + /** + * Contains the full URL for the CKEditor installation directory. + * It is possible to manually provide the base path by setting a + * global variable named CKEDITOR_BASEPATH. This global variable + * must be set before the editor script loading. + * @type String + * @example + * alert( CKEDITOR.basePath ); // "http://www.example.com/ckeditor/" (e.g.) + */ + basePath : (function() + { + // ATTENTION: fixes to this code must be ported to + // var basePath in "core/loader.js". + + // Find out the editor directory path, based on its ")' ); + } + } + + return $ && new CKEDITOR.dom.document( $.contentWindow.document ); + }, + + /** + * Copy all the attributes from one node to the other, kinda like a clone + * skipAttributes is an object with the attributes that must NOT be copied. + * @param {CKEDITOR.dom.element} dest The destination element. + * @param {Object} skipAttributes A dictionary of attributes to skip. + * @example + */ + copyAttributes : function( dest, skipAttributes ) + { + var attributes = this.$.attributes; + skipAttributes = skipAttributes || {}; + + for ( var n = 0 ; n < attributes.length ; n++ ) + { + var attribute = attributes[n]; + + // Lowercase attribute name hard rule is broken for + // some attribute on IE, e.g. CHECKED. + var attrName = attribute.nodeName.toLowerCase(), + attrValue; + + // We can set the type only once, so do it with the proper value, not copying it. + if ( attrName in skipAttributes ) + continue; + + if ( attrName == 'checked' && ( attrValue = this.getAttribute( attrName ) ) ) + dest.setAttribute( attrName, attrValue ); + // IE BUG: value attribute is never specified even if it exists. + else if ( attribute.specified || + ( CKEDITOR.env.ie && attribute.nodeValue && attrName == 'value' ) ) + { + attrValue = this.getAttribute( attrName ); + if ( attrValue === null ) + attrValue = attribute.nodeValue; + + dest.setAttribute( attrName, attrValue ); + } + } + + // The style: + if ( this.$.style.cssText !== '' ) + dest.$.style.cssText = this.$.style.cssText; + }, + + /** + * Changes the tag name of the current element. + * @param {String} newTag The new tag for the element. + */ + renameNode : function( newTag ) + { + // If it's already correct exit here. + if ( this.getName() == newTag ) + return; + + var doc = this.getDocument(); + + // Create the new node. + var newNode = new CKEDITOR.dom.element( newTag, doc ); + + // Copy all attributes. + this.copyAttributes( newNode ); + + // Move children to the new node. + this.moveChildren( newNode ); + + // Replace the node. + this.getParent() && this.$.parentNode.replaceChild( newNode.$, this.$ ); + newNode.$[ 'data-cke-expando' ] = this.$[ 'data-cke-expando' ]; + this.$ = newNode.$; + }, + + /** + * Gets a DOM tree descendant under the current node. + * @param {Array|Number} indices The child index or array of child indices under the node. + * @returns {CKEDITOR.dom.node} The specified DOM child under the current node. Null if child does not exist. + * @example + * var strong = p.getChild(0); + */ + getChild : function( indices ) + { + var rawNode = this.$; + + if ( !indices.slice ) + rawNode = rawNode.childNodes[ indices ]; + else + { + while ( indices.length > 0 && rawNode ) + rawNode = rawNode.childNodes[ indices.shift() ]; + } + + return rawNode ? new CKEDITOR.dom.node( rawNode ) : null; + }, + + getChildCount : function() + { + return this.$.childNodes.length; + }, + + disableContextMenu : function() + { + this.on( 'contextmenu', function( event ) + { + // Cancel the browser context menu. + if ( !event.data.getTarget().hasClass( 'cke_enable_context_menu' ) ) + event.data.preventDefault(); + } ); + }, + + /** + * Gets element's direction. Supports both CSS 'direction' prop and 'dir' attr. + */ + getDirection : function( useComputed ) + { + return useComputed ? + this.getComputedStyle( 'direction' ) + // Webkit: offline element returns empty direction (#8053). + || this.getDirection() + || this.getDocument().$.dir + || this.getDocument().getBody().getDirection( 1 ) + : this.getStyle( 'direction' ) || this.getAttribute( 'dir' ); + }, + + /** + * Gets, sets and removes custom data to be stored as HTML5 data-* attributes. + * @param {String} name The name of the attribute, excluding the 'data-' part. + * @param {String} [value] The value to set. If set to false, the attribute will be removed. + * @example + * element.data( 'extra-info', 'test' ); // appended the attribute data-extra-info="test" to the element + * alert( element.data( 'extra-info' ) ); // "test" + * element.data( 'extra-info', false ); // remove the data-extra-info attribute from the element + */ + data : function ( name, value ) + { + name = 'data-' + name; + if ( value === undefined ) + return this.getAttribute( name ); + else if ( value === false ) + this.removeAttribute( name ); + else + this.setAttribute( name, value ); + + return null; + } + }); + +( function() +{ + var sides = { + width : [ "border-left-width", "border-right-width","padding-left", "padding-right" ], + height : [ "border-top-width", "border-bottom-width", "padding-top", "padding-bottom" ] + }; + + function marginAndPaddingSize( type ) + { + var adjustment = 0; + for ( var i = 0, len = sides[ type ].length; i < len; i++ ) + adjustment += parseInt( this.getComputedStyle( sides [ type ][ i ] ) || 0, 10 ) || 0; + return adjustment; + } + + /** + * Sets the element size considering the box model. + * @name CKEDITOR.dom.element.prototype.setSize + * @function + * @param {String} type The dimension to set. It accepts "width" and "height". + * @param {Number} size The length unit in px. + * @param {Boolean} isBorderBox Apply the size based on the border box model. + */ + CKEDITOR.dom.element.prototype.setSize = function( type, size, isBorderBox ) + { + if ( typeof size == 'number' ) + { + if ( isBorderBox && !( CKEDITOR.env.ie && CKEDITOR.env.quirks ) ) + size -= marginAndPaddingSize.call( this, type ); + + this.setStyle( type, size + 'px' ); + } + }; + + /** + * Gets the element size, possibly considering the box model. + * @name CKEDITOR.dom.element.prototype.getSize + * @function + * @param {String} type The dimension to get. It accepts "width" and "height". + * @param {Boolean} isBorderBox Get the size based on the border box model. + */ + CKEDITOR.dom.element.prototype.getSize = function( type, isBorderBox ) + { + var size = Math.max( this.$[ 'offset' + CKEDITOR.tools.capitalize( type ) ], + this.$[ 'client' + CKEDITOR.tools.capitalize( type ) ] ) || 0; + + if ( isBorderBox ) + size -= marginAndPaddingSize.call( this, type ); + + return size; + }; +})(); Index: 3rdParty_sources/ckeditor/core/dom/elementpath.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/core/dom/elementpath.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/core/dom/elementpath.js 17 Aug 2012 14:15:42 -0000 1.1 @@ -0,0 +1,119 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +(function() +{ + // Elements that may be considered the "Block boundary" in an element path. + var pathBlockElements = { address:1,blockquote:1,dl:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,p:1,pre:1,li:1,dt:1,dd:1, legend:1,caption:1 }; + + // Elements that may be considered the "Block limit" in an element path. + var pathBlockLimitElements = { body:1,div:1,table:1,tbody:1,tr:1,td:1,th:1,form:1,fieldset:1 }; + + // Check if an element contains any block element. + var checkHasBlock = function( element ) + { + var childNodes = element.getChildren(); + + for ( var i = 0, count = childNodes.count() ; i < count ; i++ ) + { + var child = childNodes.getItem( i ); + + if ( child.type == CKEDITOR.NODE_ELEMENT && CKEDITOR.dtd.$block[ child.getName() ] ) + return true; + } + + return false; + }; + + /** + * @class + */ + CKEDITOR.dom.elementPath = function( lastNode ) + { + var block = null; + var blockLimit = null; + var elements = []; + + var e = lastNode; + + while ( e ) + { + if ( e.type == CKEDITOR.NODE_ELEMENT ) + { + if ( !this.lastElement ) + this.lastElement = e; + + var elementName = e.getName(); + if ( CKEDITOR.env.ie && e.$.scopeName != 'HTML' ) + elementName = e.$.scopeName.toLowerCase() + ':' + elementName; + + if ( !blockLimit ) + { + if ( !block && pathBlockElements[ elementName ] ) + block = e; + + if ( pathBlockLimitElements[ elementName ] ) + { + // DIV is considered the Block, if no block is available (#525) + // and if it doesn't contain other blocks. + if ( !block && elementName == 'div' && !checkHasBlock( e ) ) + block = e; + else + blockLimit = e; + } + } + + elements.push( e ); + + if ( elementName == 'body' ) + break; + } + e = e.getParent(); + } + + this.block = block; + this.blockLimit = blockLimit; + this.elements = elements; + }; +})(); + +CKEDITOR.dom.elementPath.prototype = +{ + /** + * Compares this element path with another one. + * @param {CKEDITOR.dom.elementPath} otherPath The elementPath object to be + * compared with this one. + * @returns {Boolean} "true" if the paths are equal, containing the same + * number of elements and the same elements in the same order. + */ + compare : function( otherPath ) + { + var thisElements = this.elements; + var otherElements = otherPath && otherPath.elements; + + if ( !otherElements || thisElements.length != otherElements.length ) + return false; + + for ( var i = 0 ; i < thisElements.length ; i++ ) + { + if ( !thisElements[ i ].equals( otherElements[ i ] ) ) + return false; + } + + return true; + }, + + contains : function( tagNames ) + { + var elements = this.elements; + for ( var i = 0 ; i < elements.length ; i++ ) + { + if ( elements[ i ].getName() in tagNames ) + return elements[ i ]; + } + + return null; + } +}; Index: 3rdParty_sources/ckeditor/core/dom/event.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/core/dom/event.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/core/dom/event.js 17 Aug 2012 14:15:42 -0000 1.1 @@ -0,0 +1,145 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * @fileOverview Defines the {@link CKEDITOR.dom.event} class, which + * represents the a native DOM event object. + */ + +/** + * Represents a native DOM event object. + * @constructor + * @param {Object} domEvent A native DOM event object. + * @example + */ +CKEDITOR.dom.event = function( domEvent ) +{ + /** + * The native DOM event object represented by this class instance. + * @type Object + * @example + */ + this.$ = domEvent; +}; + +CKEDITOR.dom.event.prototype = +{ + /** + * Gets the key code associated to the event. + * @returns {Number} The key code. + * @example + * alert( event.getKey() ); "65" is "a" has been pressed + */ + getKey : function() + { + return this.$.keyCode || this.$.which; + }, + + /** + * Gets a number represeting the combination of the keys pressed during the + * event. It is the sum with the current key code and the {@link CKEDITOR.CTRL}, + * {@link CKEDITOR.SHIFT} and {@link CKEDITOR.ALT} constants. + * @returns {Number} The number representing the keys combination. + * @example + * alert( event.getKeystroke() == 65 ); // "a" key + * alert( event.getKeystroke() == CKEDITOR.CTRL + 65 ); // CTRL + "a" key + * alert( event.getKeystroke() == CKEDITOR.CTRL + CKEDITOR.SHIFT + 65 ); // CTRL + SHIFT + "a" key + */ + getKeystroke : function() + { + var keystroke = this.getKey(); + + if ( this.$.ctrlKey || this.$.metaKey ) + keystroke += CKEDITOR.CTRL; + + if ( this.$.shiftKey ) + keystroke += CKEDITOR.SHIFT; + + if ( this.$.altKey ) + keystroke += CKEDITOR.ALT; + + return keystroke; + }, + + /** + * Prevents the original behavior of the event to happen. It can optionally + * stop propagating the event in the event chain. + * @param {Boolean} [stopPropagation] Stop propagating this event in the + * event chain. + * @example + * var element = CKEDITOR.document.getById( 'myElement' ); + * element.on( 'click', function( ev ) + * { + * // The DOM event object is passed by the "data" property. + * var domEvent = ev.data; + * // Prevent the click to chave any effect in the element. + * domEvent.preventDefault(); + * }); + */ + preventDefault : function( stopPropagation ) + { + var $ = this.$; + if ( $.preventDefault ) + $.preventDefault(); + else + $.returnValue = false; + + if ( stopPropagation ) + this.stopPropagation(); + }, + + stopPropagation : function() + { + var $ = this.$; + if ( $.stopPropagation ) + $.stopPropagation(); + else + $.cancelBubble = true; + }, + + /** + * Returns the DOM node where the event was targeted to. + * @returns {CKEDITOR.dom.node} The target DOM node. + * @example + * var element = CKEDITOR.document.getById( 'myElement' ); + * element.on( 'click', function( ev ) + * { + * // The DOM event object is passed by the "data" property. + * var domEvent = ev.data; + * // Add a CSS class to the event target. + * domEvent.getTarget().addClass( 'clicked' ); + * }); + */ + + getTarget : function() + { + var rawNode = this.$.target || this.$.srcElement; + return rawNode ? new CKEDITOR.dom.node( rawNode ) : null; + } +}; + +// For the followind constants, we need to go over the Unicode boundaries +// (0x10FFFF) to avoid collision. + +/** + * CTRL key (0x110000). + * @constant + * @example + */ +CKEDITOR.CTRL = 0x110000; + +/** + * SHIFT key (0x220000). + * @constant + * @example + */ +CKEDITOR.SHIFT = 0x220000; + +/** + * ALT key (0x440000). + * @constant + * @example + */ +CKEDITOR.ALT = 0x440000; Index: 3rdParty_sources/ckeditor/core/dom/node.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/core/dom/node.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/core/dom/node.js 17 Aug 2012 14:15:42 -0000 1.1 @@ -0,0 +1,696 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * @fileOverview Defines the {@link CKEDITOR.dom.node} class which is the base + * class for classes that represent DOM nodes. + */ + +/** + * Base class for classes representing DOM nodes. This constructor may return + * an instance of a class that inherits from this class, like + * {@link CKEDITOR.dom.element} or {@link CKEDITOR.dom.text}. + * @augments CKEDITOR.dom.domObject + * @param {Object} domNode A native DOM node. + * @constructor + * @see CKEDITOR.dom.element + * @see CKEDITOR.dom.text + * @example + */ +CKEDITOR.dom.node = function( domNode ) +{ + if ( domNode ) + { + switch ( domNode.nodeType ) + { + // Safari don't consider document as element node type. (#3389) + case CKEDITOR.NODE_DOCUMENT : + return new CKEDITOR.dom.document( domNode ); + + case CKEDITOR.NODE_ELEMENT : + return new CKEDITOR.dom.element( domNode ); + + case CKEDITOR.NODE_TEXT : + return new CKEDITOR.dom.text( domNode ); + } + + // Call the base constructor. + CKEDITOR.dom.domObject.call( this, domNode ); + } + + return this; +}; + +CKEDITOR.dom.node.prototype = new CKEDITOR.dom.domObject(); + +/** + * Element node type. + * @constant + * @example + */ +CKEDITOR.NODE_ELEMENT = 1; + +/** + * Document node type. + * @constant + * @example + */ +CKEDITOR.NODE_DOCUMENT = 9; + +/** + * Text node type. + * @constant + * @example + */ +CKEDITOR.NODE_TEXT = 3; + +/** + * Comment node type. + * @constant + * @example + */ +CKEDITOR.NODE_COMMENT = 8; + +CKEDITOR.NODE_DOCUMENT_FRAGMENT = 11; + +CKEDITOR.POSITION_IDENTICAL = 0; +CKEDITOR.POSITION_DISCONNECTED = 1; +CKEDITOR.POSITION_FOLLOWING = 2; +CKEDITOR.POSITION_PRECEDING = 4; +CKEDITOR.POSITION_IS_CONTAINED = 8; +CKEDITOR.POSITION_CONTAINS = 16; + +CKEDITOR.tools.extend( CKEDITOR.dom.node.prototype, + /** @lends CKEDITOR.dom.node.prototype */ + { + /** + * Makes this node a child of another element. + * @param {CKEDITOR.dom.element} element The target element to which + * this node will be appended. + * @returns {CKEDITOR.dom.element} The target element. + * @example + * var p = new CKEDITOR.dom.element( 'p' ); + * var strong = new CKEDITOR.dom.element( 'strong' ); + * strong.appendTo( p ); + * + * // result: "<p><strong></strong></p>" + */ + appendTo : function( element, toStart ) + { + element.append( this, toStart ); + return element; + }, + + clone : function( includeChildren, cloneId ) + { + var $clone = this.$.cloneNode( includeChildren ); + + var removeIds = function( node ) + { + if ( node.nodeType != CKEDITOR.NODE_ELEMENT ) + return; + + if ( !cloneId ) + node.removeAttribute( 'id', false ); + node.removeAttribute( 'data-cke-expando', false ); + + if ( includeChildren ) + { + var childs = node.childNodes; + for ( var i=0; i < childs.length; i++ ) + removeIds( childs[ i ] ); + } + }; + + // The "id" attribute should never be cloned to avoid duplication. + removeIds( $clone ); + + return new CKEDITOR.dom.node( $clone ); + }, + + hasPrevious : function() + { + return !!this.$.previousSibling; + }, + + hasNext : function() + { + return !!this.$.nextSibling; + }, + + /** + * Inserts this element after a node. + * @param {CKEDITOR.dom.node} node The node that will precede this element. + * @returns {CKEDITOR.dom.node} The node preceding this one after + * insertion. + * @example + * var em = new CKEDITOR.dom.element( 'em' ); + * var strong = new CKEDITOR.dom.element( 'strong' ); + * strong.insertAfter( em ); + * + * // result: "<em></em><strong></strong>" + */ + insertAfter : function( node ) + { + node.$.parentNode.insertBefore( this.$, node.$.nextSibling ); + return node; + }, + + /** + * Inserts this element before a node. + * @param {CKEDITOR.dom.node} node The node that will succeed this element. + * @returns {CKEDITOR.dom.node} The node being inserted. + * @example + * var em = new CKEDITOR.dom.element( 'em' ); + * var strong = new CKEDITOR.dom.element( 'strong' ); + * strong.insertBefore( em ); + * + * // result: "<strong></strong><em></em>" + */ + insertBefore : function( node ) + { + node.$.parentNode.insertBefore( this.$, node.$ ); + return node; + }, + + insertBeforeMe : function( node ) + { + this.$.parentNode.insertBefore( node.$, this.$ ); + return node; + }, + + /** + * Retrieves a uniquely identifiable tree address for this node. + * The tree address returned is an array of integers, with each integer + * indicating a child index of a DOM node, starting from + * document.documentElement. + * + * For example, assuming <body> is the second child + * of <html> (<head> being the first), + * and we would like to address the third child under the + * fourth child of <body>, the tree address returned would be: + * [1, 3, 2] + * + * The tree address cannot be used for finding back the DOM tree node once + * the DOM tree structure has been modified. + */ + getAddress : function( normalized ) + { + var address = []; + var $documentElement = this.getDocument().$.documentElement; + var node = this.$; + + while ( node && node != $documentElement ) + { + var parentNode = node.parentNode; + + if ( parentNode ) + { + // Get the node index. For performance, call getIndex + // directly, instead of creating a new node object. + address.unshift( this.getIndex.call( { $ : node }, normalized ) ); + } + + node = parentNode; + } + + return address; + }, + + /** + * Gets the document containing this element. + * @returns {CKEDITOR.dom.document} The document. + * @example + * var element = CKEDITOR.document.getById( 'example' ); + * alert( element.getDocument().equals( CKEDITOR.document ) ); // "true" + */ + getDocument : function() + { + return new CKEDITOR.dom.document( this.$.ownerDocument || this.$.parentNode.ownerDocument ); + }, + + getIndex : function( normalized ) + { + // Attention: getAddress depends on this.$ + + var current = this.$, + index = 0; + + while ( ( current = current.previousSibling ) ) + { + // When normalizing, do not count it if this is an + // empty text node or if it's a text node following another one. + if ( normalized && current.nodeType == 3 && + ( !current.nodeValue.length || + ( current.previousSibling && current.previousSibling.nodeType == 3 ) ) ) + { + continue; + } + + index++; + } + + return index; + }, + + getNextSourceNode : function( startFromSibling, nodeType, guard ) + { + // If "guard" is a node, transform it in a function. + if ( guard && !guard.call ) + { + var guardNode = guard; + guard = function( node ) + { + return !node.equals( guardNode ); + }; + } + + var node = ( !startFromSibling && this.getFirst && this.getFirst() ), + parent; + + // Guarding when we're skipping the current element( no children or 'startFromSibling' ). + // send the 'moving out' signal even we don't actually dive into. + if ( !node ) + { + if ( this.type == CKEDITOR.NODE_ELEMENT && guard && guard( this, true ) === false ) + return null; + node = this.getNext(); + } + + while ( !node && ( parent = ( parent || this ).getParent() ) ) + { + // The guard check sends the "true" paramenter to indicate that + // we are moving "out" of the element. + if ( guard && guard( parent, true ) === false ) + return null; + + node = parent.getNext(); + } + + if ( !node ) + return null; + + if ( guard && guard( node ) === false ) + return null; + + if ( nodeType && nodeType != node.type ) + return node.getNextSourceNode( false, nodeType, guard ); + + return node; + }, + + getPreviousSourceNode : function( startFromSibling, nodeType, guard ) + { + if ( guard && !guard.call ) + { + var guardNode = guard; + guard = function( node ) + { + return !node.equals( guardNode ); + }; + } + + var node = ( !startFromSibling && this.getLast && this.getLast() ), + parent; + + // Guarding when we're skipping the current element( no children or 'startFromSibling' ). + // send the 'moving out' signal even we don't actually dive into. + if ( !node ) + { + if ( this.type == CKEDITOR.NODE_ELEMENT && guard && guard( this, true ) === false ) + return null; + node = this.getPrevious(); + } + + while ( !node && ( parent = ( parent || this ).getParent() ) ) + { + // The guard check sends the "true" paramenter to indicate that + // we are moving "out" of the element. + if ( guard && guard( parent, true ) === false ) + return null; + + node = parent.getPrevious(); + } + + if ( !node ) + return null; + + if ( guard && guard( node ) === false ) + return null; + + if ( nodeType && node.type != nodeType ) + return node.getPreviousSourceNode( false, nodeType, guard ); + + return node; + }, + + getPrevious : function( evaluator ) + { + var previous = this.$, retval; + do + { + previous = previous.previousSibling; + retval = previous && new CKEDITOR.dom.node( previous ); + } + while ( retval && evaluator && !evaluator( retval ) ) + return retval; + }, + + /** + * Gets the node that follows this element in its parent's child list. + * @param {Function} evaluator Filtering the result node. + * @returns {CKEDITOR.dom.node} The next node or null if not available. + * @example + * var element = CKEDITOR.dom.element.createFromHtml( '<div><b>Example</b> <i>next</i></div>' ); + * var first = element.getFirst().getNext(); + * alert( first.getName() ); // "i" + */ + getNext : function( evaluator ) + { + var next = this.$, retval; + do + { + next = next.nextSibling; + retval = next && new CKEDITOR.dom.node( next ); + } + while ( retval && evaluator && !evaluator( retval ) ) + return retval; + }, + + /** + * Gets the parent element for this node. + * @returns {CKEDITOR.dom.element} The parent element. + * @example + * var node = editor.document.getBody().getFirst(); + * var parent = node.getParent(); + * alert( node.getName() ); // "body" + */ + getParent : function() + { + var parent = this.$.parentNode; + return ( parent && parent.nodeType == 1 ) ? new CKEDITOR.dom.node( parent ) : null; + }, + + getParents : function( closerFirst ) + { + var node = this; + var parents = []; + + do + { + parents[ closerFirst ? 'push' : 'unshift' ]( node ); + } + while ( ( node = node.getParent() ) ) + + return parents; + }, + + getCommonAncestor : function( node ) + { + if ( node.equals( this ) ) + return this; + + if ( node.contains && node.contains( this ) ) + return node; + + var start = this.contains ? this : this.getParent(); + + do + { + if ( start.contains( node ) ) + return start; + } + while ( ( start = start.getParent() ) ); + + return null; + }, + + getPosition : function( otherNode ) + { + var $ = this.$; + var $other = otherNode.$; + + if ( $.compareDocumentPosition ) + return $.compareDocumentPosition( $other ); + + // IE and Safari have no support for compareDocumentPosition. + + if ( $ == $other ) + return CKEDITOR.POSITION_IDENTICAL; + + // Only element nodes support contains and sourceIndex. + if ( this.type == CKEDITOR.NODE_ELEMENT && otherNode.type == CKEDITOR.NODE_ELEMENT ) + { + if ( $.contains ) + { + if ( $.contains( $other ) ) + return CKEDITOR.POSITION_CONTAINS + CKEDITOR.POSITION_PRECEDING; + + if ( $other.contains( $ ) ) + return CKEDITOR.POSITION_IS_CONTAINED + CKEDITOR.POSITION_FOLLOWING; + } + + if ( 'sourceIndex' in $ ) + { + return ( $.sourceIndex < 0 || $other.sourceIndex < 0 ) ? CKEDITOR.POSITION_DISCONNECTED : + ( $.sourceIndex < $other.sourceIndex ) ? CKEDITOR.POSITION_PRECEDING : + CKEDITOR.POSITION_FOLLOWING; + } + } + + // For nodes that don't support compareDocumentPosition, contains + // or sourceIndex, their "address" is compared. + + var addressOfThis = this.getAddress(), + addressOfOther = otherNode.getAddress(), + minLevel = Math.min( addressOfThis.length, addressOfOther.length ); + + // Determinate preceed/follow relationship. + for ( var i = 0 ; i <= minLevel - 1 ; i++ ) + { + if ( addressOfThis[ i ] != addressOfOther[ i ] ) + { + if ( i < minLevel ) + { + return addressOfThis[ i ] < addressOfOther[ i ] ? + CKEDITOR.POSITION_PRECEDING : CKEDITOR.POSITION_FOLLOWING; + } + break; + } + } + + // Determinate contains/contained relationship. + return ( addressOfThis.length < addressOfOther.length ) ? + CKEDITOR.POSITION_CONTAINS + CKEDITOR.POSITION_PRECEDING : + CKEDITOR.POSITION_IS_CONTAINED + CKEDITOR.POSITION_FOLLOWING; + }, + + /** + * Gets the closest ancestor node of this node, specified by its name. + * @param {String} reference The name of the ancestor node to search or + * an object with the node names to search for. + * @param {Boolean} [includeSelf] Whether to include the current + * node in the search. + * @returns {CKEDITOR.dom.node} The located ancestor node or null if not found. + * @since 3.6.1 + * @example + * // Suppose we have the following HTML structure: + * // <div id="outer"><div id="inner"><p><b>Some text</b></p></div></div> + * // If node == <b> + * ascendant = node.getAscendant( 'div' ); // ascendant == <div id="inner"> + * ascendant = node.getAscendant( 'b' ); // ascendant == null + * ascendant = node.getAscendant( 'b', true ); // ascendant == <b> + * ascendant = node.getAscendant( { div: 1, p: 1} ); // Searches for the first 'div' or 'p': ascendant == <div id="inner"> + */ + getAscendant : function( reference, includeSelf ) + { + var $ = this.$, + name; + + if ( !includeSelf ) + $ = $.parentNode; + + while ( $ ) + { + if ( $.nodeName && ( name = $.nodeName.toLowerCase(), ( typeof reference == 'string' ? name == reference : name in reference ) ) ) + return new CKEDITOR.dom.node( $ ); + + $ = $.parentNode; + } + return null; + }, + + hasAscendant : function( name, includeSelf ) + { + var $ = this.$; + + if ( !includeSelf ) + $ = $.parentNode; + + while ( $ ) + { + if ( $.nodeName && $.nodeName.toLowerCase() == name ) + return true; + + $ = $.parentNode; + } + return false; + }, + + move : function( target, toStart ) + { + target.append( this.remove(), toStart ); + }, + + /** + * Removes this node from the document DOM. + * @param {Boolean} [preserveChildren] Indicates that the children + * elements must remain in the document, removing only the outer + * tags. + * @example + * var element = CKEDITOR.dom.element.getById( 'MyElement' ); + * element.remove(); + */ + remove : function( preserveChildren ) + { + var $ = this.$; + var parent = $.parentNode; + + if ( parent ) + { + if ( preserveChildren ) + { + // Move all children before the node. + for ( var child ; ( child = $.firstChild ) ; ) + { + parent.insertBefore( $.removeChild( child ), $ ); + } + } + + parent.removeChild( $ ); + } + + return this; + }, + + replace : function( nodeToReplace ) + { + this.insertBefore( nodeToReplace ); + nodeToReplace.remove(); + }, + + trim : function() + { + this.ltrim(); + this.rtrim(); + }, + + ltrim : function() + { + var child; + while ( this.getFirst && ( child = this.getFirst() ) ) + { + if ( child.type == CKEDITOR.NODE_TEXT ) + { + var trimmed = CKEDITOR.tools.ltrim( child.getText() ), + originalLength = child.getLength(); + + if ( !trimmed ) + { + child.remove(); + continue; + } + else if ( trimmed.length < originalLength ) + { + child.split( originalLength - trimmed.length ); + + // IE BUG: child.remove() may raise JavaScript errors here. (#81) + this.$.removeChild( this.$.firstChild ); + } + } + break; + } + }, + + rtrim : function() + { + var child; + while ( this.getLast && ( child = this.getLast() ) ) + { + if ( child.type == CKEDITOR.NODE_TEXT ) + { + var trimmed = CKEDITOR.tools.rtrim( child.getText() ), + originalLength = child.getLength(); + + if ( !trimmed ) + { + child.remove(); + continue; + } + else if ( trimmed.length < originalLength ) + { + child.split( trimmed.length ); + + // IE BUG: child.getNext().remove() may raise JavaScript errors here. + // (#81) + this.$.lastChild.parentNode.removeChild( this.$.lastChild ); + } + } + break; + } + + if ( !CKEDITOR.env.ie && !CKEDITOR.env.opera ) + { + child = this.$.lastChild; + + if ( child && child.type == 1 && child.nodeName.toLowerCase() == 'br' ) + { + // Use "eChildNode.parentNode" instead of "node" to avoid IE bug (#324). + child.parentNode.removeChild( child ) ; + } + } + }, + + /** + * Checks if this node is read-only (should not be changed). + * @returns {Boolean} + * @since 3.5 + * @example + * // For the following HTML: + * // <div contenteditable="false">Some <b>text</b></div> + * + * // If "ele" is the above <div> + * ele.isReadOnly(); // true + */ + isReadOnly : function() + { + var element = this; + if ( this.type != CKEDITOR.NODE_ELEMENT ) + element = this.getParent(); + + if ( element && typeof element.$.isContentEditable != 'undefined' ) + return ! ( element.$.isContentEditable || element.data( 'cke-editable' ) ); + else + { + // Degrade for old browsers which don't support "isContentEditable", e.g. FF3 + var current = element; + while( current ) + { + if ( current.is( 'body' ) || !!current.data( 'cke-editable' ) ) + break; + + if ( current.getAttribute( 'contentEditable' ) == 'false' ) + return true; + else if ( current.getAttribute( 'contentEditable' ) == 'true' ) + break; + + current = current.getParent(); + } + + return false; + } + } + } +); Index: 3rdParty_sources/ckeditor/core/dom/nodelist.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/core/dom/nodelist.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/core/dom/nodelist.js 17 Aug 2012 14:15:43 -0000 1.1 @@ -0,0 +1,26 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * @class + */ +CKEDITOR.dom.nodeList = function( nativeList ) +{ + this.$ = nativeList; +}; + +CKEDITOR.dom.nodeList.prototype = +{ + count : function() + { + return this.$.length; + }, + + getItem : function( index ) + { + var $node = this.$[ index ]; + return $node ? new CKEDITOR.dom.node( $node ) : null; + } +}; Index: 3rdParty_sources/ckeditor/core/dom/range.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/core/dom/range.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/core/dom/range.js 17 Aug 2012 14:15:43 -0000 1.1 @@ -0,0 +1,2054 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * Creates a CKEDITOR.dom.range instance that can be used inside a specific + * DOM Document. + * @class Represents a delimited piece of content in a DOM Document. + * It is contiguous in the sense that it can be characterized as selecting all + * of the content between a pair of boundary-points.
+ *
+ * This class shares much of the W3C + *
Document Object Model Range + * ideas and features, adding several range manipulation tools to it, but it's + * not intended to be compatible with it. + * @param {CKEDITOR.dom.document} document The document into which the range + * features will be available. + * @example + * // Create a range for the entire contents of the editor document body. + * var range = new CKEDITOR.dom.range( editor.document ); + * range.selectNodeContents( editor.document.getBody() ); + * // Delete the contents. + * range.deleteContents(); + */ +CKEDITOR.dom.range = function( document ) +{ + /** + * Node within which the range begins. + * @type {CKEDITOR.NODE_ELEMENT|CKEDITOR.NODE_TEXT} + * @example + * var range = new CKEDITOR.dom.range( editor.document ); + * range.selectNodeContents( editor.document.getBody() ); + * alert( range.startContainer.getName() ); // "body" + */ + this.startContainer = null; + + /** + * Offset within the starting node of the range. + * @type {Number} + * @example + * var range = new CKEDITOR.dom.range( editor.document ); + * range.selectNodeContents( editor.document.getBody() ); + * alert( range.startOffset ); // "0" + */ + this.startOffset = null; + + /** + * Node within which the range ends. + * @type {CKEDITOR.NODE_ELEMENT|CKEDITOR.NODE_TEXT} + * @example + * var range = new CKEDITOR.dom.range( editor.document ); + * range.selectNodeContents( editor.document.getBody() ); + * alert( range.endContainer.getName() ); // "body" + */ + this.endContainer = null; + + /** + * Offset within the ending node of the range. + * @type {Number} + * @example + * var range = new CKEDITOR.dom.range( editor.document ); + * range.selectNodeContents( editor.document.getBody() ); + * alert( range.endOffset ); // == editor.document.getBody().getChildCount() + */ + this.endOffset = null; + + /** + * Indicates that this is a collapsed range. A collapsed range has it's + * start and end boudaries at the very same point so nothing is contained + * in it. + * @example + * var range = new CKEDITOR.dom.range( editor.document ); + * range.selectNodeContents( editor.document.getBody() ); + * alert( range.collapsed ); // "false" + * range.collapse(); + * alert( range.collapsed ); // "true" + */ + this.collapsed = true; + + /** + * The document within which the range can be used. + * @type {CKEDITOR.dom.document} + * @example + * // Selects the body contents of the range document. + * range.selectNodeContents( range.document.getBody() ); + */ + this.document = document; +}; + +(function() +{ + // Updates the "collapsed" property for the given range object. + var updateCollapsed = function( range ) + { + range.collapsed = ( + range.startContainer && + range.endContainer && + range.startContainer.equals( range.endContainer ) && + range.startOffset == range.endOffset ); + }; + + // This is a shared function used to delete, extract and clone the range + // contents. + // V2 + var execContentsAction = function( range, action, docFrag, mergeThen ) + { + range.optimizeBookmark(); + + var startNode = range.startContainer; + var endNode = range.endContainer; + + var startOffset = range.startOffset; + var endOffset = range.endOffset; + + var removeStartNode; + var removeEndNode; + + // For text containers, we must simply split the node and point to the + // second part. The removal will be handled by the rest of the code . + if ( endNode.type == CKEDITOR.NODE_TEXT ) + endNode = endNode.split( endOffset ); + else + { + // If the end container has children and the offset is pointing + // to a child, then we should start from it. + if ( endNode.getChildCount() > 0 ) + { + // If the offset points after the last node. + if ( endOffset >= endNode.getChildCount() ) + { + // Let's create a temporary node and mark it for removal. + endNode = endNode.append( range.document.createText( '' ) ); + removeEndNode = true; + } + else + endNode = endNode.getChild( endOffset ); + } + } + + // For text containers, we must simply split the node. The removal will + // be handled by the rest of the code . + if ( startNode.type == CKEDITOR.NODE_TEXT ) + { + startNode.split( startOffset ); + + // In cases the end node is the same as the start node, the above + // splitting will also split the end, so me must move the end to + // the second part of the split. + if ( startNode.equals( endNode ) ) + endNode = startNode.getNext(); + } + else + { + // If the start container has children and the offset is pointing + // to a child, then we should start from its previous sibling. + + // If the offset points to the first node, we don't have a + // sibling, so let's use the first one, but mark it for removal. + if ( !startOffset ) + { + // Let's create a temporary node and mark it for removal. + startNode = startNode.getFirst().insertBeforeMe( range.document.createText( '' ) ); + removeStartNode = true; + } + else if ( startOffset >= startNode.getChildCount() ) + { + // Let's create a temporary node and mark it for removal. + startNode = startNode.append( range.document.createText( '' ) ); + removeStartNode = true; + } + else + startNode = startNode.getChild( startOffset ).getPrevious(); + } + + // Get the parent nodes tree for the start and end boundaries. + var startParents = startNode.getParents(); + var endParents = endNode.getParents(); + + // Compare them, to find the top most siblings. + var i, topStart, topEnd; + + for ( i = 0 ; i < startParents.length ; i++ ) + { + topStart = startParents[ i ]; + topEnd = endParents[ i ]; + + // The compared nodes will match until we find the top most + // siblings (different nodes that have the same parent). + // "i" will hold the index in the parents array for the top + // most element. + if ( !topStart.equals( topEnd ) ) + break; + } + + var clone = docFrag, levelStartNode, levelClone, currentNode, currentSibling; + + // Remove all successive sibling nodes for every node in the + // startParents tree. + for ( var j = i ; j < startParents.length ; j++ ) + { + levelStartNode = startParents[j]; + + // For Extract and Clone, we must clone this level. + if ( clone && !levelStartNode.equals( startNode ) ) // action = 0 = Delete + levelClone = clone.append( levelStartNode.clone() ); + + currentNode = levelStartNode.getNext(); + + while ( currentNode ) + { + // Stop processing when the current node matches a node in the + // endParents tree or if it is the endNode. + if ( currentNode.equals( endParents[ j ] ) || currentNode.equals( endNode ) ) + break; + + // Cache the next sibling. + currentSibling = currentNode.getNext(); + + // If cloning, just clone it. + if ( action == 2 ) // 2 = Clone + clone.append( currentNode.clone( true ) ); + else + { + // Both Delete and Extract will remove the node. + currentNode.remove(); + + // When Extracting, move the removed node to the docFrag. + if ( action == 1 ) // 1 = Extract + clone.append( currentNode ); + } + + currentNode = currentSibling; + } + + if ( clone ) + clone = levelClone; + } + + clone = docFrag; + + // Remove all previous sibling nodes for every node in the + // endParents tree. + for ( var k = i ; k < endParents.length ; k++ ) + { + levelStartNode = endParents[ k ]; + + // For Extract and Clone, we must clone this level. + if ( action > 0 && !levelStartNode.equals( endNode ) ) // action = 0 = Delete + levelClone = clone.append( levelStartNode.clone() ); + + // The processing of siblings may have already been done by the parent. + if ( !startParents[ k ] || levelStartNode.$.parentNode != startParents[ k ].$.parentNode ) + { + currentNode = levelStartNode.getPrevious(); + + while ( currentNode ) + { + // Stop processing when the current node matches a node in the + // startParents tree or if it is the startNode. + if ( currentNode.equals( startParents[ k ] ) || currentNode.equals( startNode ) ) + break; + + // Cache the next sibling. + currentSibling = currentNode.getPrevious(); + + // If cloning, just clone it. + if ( action == 2 ) // 2 = Clone + clone.$.insertBefore( currentNode.$.cloneNode( true ), clone.$.firstChild ) ; + else + { + // Both Delete and Extract will remove the node. + currentNode.remove(); + + // When Extracting, mode the removed node to the docFrag. + if ( action == 1 ) // 1 = Extract + clone.$.insertBefore( currentNode.$, clone.$.firstChild ); + } + + currentNode = currentSibling; + } + } + + if ( clone ) + clone = levelClone; + } + + if ( action == 2 ) // 2 = Clone. + { + // No changes in the DOM should be done, so fix the split text (if any). + + var startTextNode = range.startContainer; + if ( startTextNode.type == CKEDITOR.NODE_TEXT ) + { + startTextNode.$.data += startTextNode.$.nextSibling.data; + startTextNode.$.parentNode.removeChild( startTextNode.$.nextSibling ); + } + + var endTextNode = range.endContainer; + if ( endTextNode.type == CKEDITOR.NODE_TEXT && endTextNode.$.nextSibling ) + { + endTextNode.$.data += endTextNode.$.nextSibling.data; + endTextNode.$.parentNode.removeChild( endTextNode.$.nextSibling ); + } + } + else + { + // Collapse the range. + + // If a node has been partially selected, collapse the range between + // topStart and topEnd. Otherwise, simply collapse it to the start. (W3C specs). + if ( topStart && topEnd && ( startNode.$.parentNode != topStart.$.parentNode || endNode.$.parentNode != topEnd.$.parentNode ) ) + { + var endIndex = topEnd.getIndex(); + + // If the start node is to be removed, we must correct the + // index to reflect the removal. + if ( removeStartNode && topEnd.$.parentNode == startNode.$.parentNode ) + endIndex--; + + // Merge splitted parents. + if ( mergeThen && topStart.type == CKEDITOR.NODE_ELEMENT ) + { + var span = CKEDITOR.dom.element.createFromHtml( ' ', range.document ); + span.insertAfter( topStart ); + topStart.mergeSiblings( false ); + range.moveToBookmark( { startNode : span } ); + } + else + range.setStart( topEnd.getParent(), endIndex ); + } + + // Collapse it to the start. + range.collapse( true ); + } + + // Cleanup any marked node. + if ( removeStartNode ) + startNode.remove(); + + if ( removeEndNode && endNode.$.parentNode ) + endNode.remove(); + }; + + var inlineChildReqElements = { abbr:1,acronym:1,b:1,bdo:1,big:1,cite:1,code:1,del:1,dfn:1,em:1,font:1,i:1,ins:1,label:1,kbd:1,q:1,samp:1,small:1,span:1,strike:1,strong:1,sub:1,sup:1,tt:1,u:1,'var':1 }; + + // Creates the appropriate node evaluator for the dom walker used inside + // check(Start|End)OfBlock. + function getCheckStartEndBlockEvalFunction( isStart ) + { + var hadBr = false, bookmarkEvaluator = CKEDITOR.dom.walker.bookmark( true ); + return function( node ) + { + // First ignore bookmark nodes. + if ( bookmarkEvaluator( node ) ) + return true; + + if ( node.type == CKEDITOR.NODE_TEXT ) + { + // If there's any visible text, then we're not at the start. + if ( node.hasAscendant( 'pre' ) || CKEDITOR.tools.trim( node.getText() ).length ) + return false; + } + else if ( node.type == CKEDITOR.NODE_ELEMENT ) + { + // If there are non-empty inline elements (e.g. ), then we're not + // at the start. + if ( !inlineChildReqElements[ node.getName() ] ) + { + // If we're working at the end-of-block, forgive the first
in non-IE + // browsers. + if ( !isStart && !CKEDITOR.env.ie && node.getName() == 'br' && !hadBr ) + hadBr = true; + else + return false; + } + } + return true; + }; + } + + // Evaluator for CKEDITOR.dom.element::checkBoundaryOfElement, reject any + // text node and non-empty elements unless it's being bookmark text. + function elementBoundaryEval( node ) + { + // Reject any text node unless it's being bookmark + // OR it's spaces. (#3883) + return node.type != CKEDITOR.NODE_TEXT + && node.getName() in CKEDITOR.dtd.$removeEmpty + || !CKEDITOR.tools.trim( node.getText() ) + || !!node.getParent().data( 'cke-bookmark' ); + } + + var whitespaceEval = new CKEDITOR.dom.walker.whitespaces(), + bookmarkEval = new CKEDITOR.dom.walker.bookmark(); + + function nonWhitespaceOrBookmarkEval( node ) + { + // Whitespaces and bookmark nodes are to be ignored. + return !whitespaceEval( node ) && !bookmarkEval( node ); + } + + CKEDITOR.dom.range.prototype = + { + clone : function() + { + var clone = new CKEDITOR.dom.range( this.document ); + + clone.startContainer = this.startContainer; + clone.startOffset = this.startOffset; + clone.endContainer = this.endContainer; + clone.endOffset = this.endOffset; + clone.collapsed = this.collapsed; + + return clone; + }, + + collapse : function( toStart ) + { + if ( toStart ) + { + this.endContainer = this.startContainer; + this.endOffset = this.startOffset; + } + else + { + this.startContainer = this.endContainer; + this.startOffset = this.endOffset; + } + + this.collapsed = true; + }, + + /** + * The content nodes of the range are cloned and added to a document fragment, which is returned. + * Note: Text selection may lost after invoking this method. (caused by text node splitting). + */ + cloneContents : function() + { + var docFrag = new CKEDITOR.dom.documentFragment( this.document ); + + if ( !this.collapsed ) + execContentsAction( this, 2, docFrag ); + + return docFrag; + }, + + /** + * Deletes the content nodes of the range permanently from the DOM tree. + * @param {Boolean} [mergeThen] Merge any splitted elements result in DOM true due to partial selection. + */ + deleteContents : function( mergeThen ) + { + if ( this.collapsed ) + return; + + execContentsAction( this, 0, null, mergeThen ); + }, + + /** + * The content nodes of the range are cloned and added to a document fragment, + * meanwhile they're removed permanently from the DOM tree. + * @param {Boolean} [mergeThen] Merge any splitted elements result in DOM true due to partial selection. + */ + extractContents : function( mergeThen ) + { + var docFrag = new CKEDITOR.dom.documentFragment( this.document ); + + if ( !this.collapsed ) + execContentsAction( this, 1, docFrag, mergeThen ); + + return docFrag; + }, + + /** + * Creates a bookmark object, which can be later used to restore the + * range by using the moveToBookmark function. + * This is an "intrusive" way to create a bookmark. It includes tags + * in the range boundaries. The advantage of it is that it is possible to + * handle DOM mutations when moving back to the bookmark. + * Attention: the inclusion of nodes in the DOM is a design choice and + * should not be changed as there are other points in the code that may be + * using those nodes to perform operations. See GetBookmarkNode. + * @param {Boolean} [serializable] Indicates that the bookmark nodes + * must contain ids, which can be used to restore the range even + * when these nodes suffer mutations (like a clonation or innerHTML + * change). + * @returns {Object} And object representing a bookmark. + */ + createBookmark : function( serializable ) + { + var startNode, endNode; + var baseId; + var clone; + var collapsed = this.collapsed; + + startNode = this.document.createElement( 'span' ); + startNode.data( 'cke-bookmark', 1 ); + startNode.setStyle( 'display', 'none' ); + + // For IE, it must have something inside, otherwise it may be + // removed during DOM operations. + startNode.setHtml( ' ' ); + + if ( serializable ) + { + baseId = 'cke_bm_' + CKEDITOR.tools.getNextNumber(); + startNode.setAttribute( 'id', baseId + 'S' ); + } + + // If collapsed, the endNode will not be created. + if ( !collapsed ) + { + endNode = startNode.clone(); + endNode.setHtml( ' ' ); + + if ( serializable ) + endNode.setAttribute( 'id', baseId + 'E' ); + + clone = this.clone(); + clone.collapse(); + clone.insertNode( endNode ); + } + + clone = this.clone(); + clone.collapse( true ); + clone.insertNode( startNode ); + + // Update the range position. + if ( endNode ) + { + this.setStartAfter( startNode ); + this.setEndBefore( endNode ); + } + else + this.moveToPosition( startNode, CKEDITOR.POSITION_AFTER_END ); + + return { + startNode : serializable ? baseId + 'S' : startNode, + endNode : serializable ? baseId + 'E' : endNode, + serializable : serializable, + collapsed : collapsed + }; + }, + + /** + * Creates a "non intrusive" and "mutation sensible" bookmark. This + * kind of bookmark should be used only when the DOM is supposed to + * remain stable after its creation. + * @param {Boolean} [normalized] Indicates that the bookmark must + * normalized. When normalized, the successive text nodes are + * considered a single node. To sucessful load a normalized + * bookmark, the DOM tree must be also normalized before calling + * moveToBookmark. + * @returns {Object} An object representing the bookmark. + */ + createBookmark2 : function( normalized ) + { + var startContainer = this.startContainer, + endContainer = this.endContainer; + + var startOffset = this.startOffset, + endOffset = this.endOffset; + + var collapsed = this.collapsed; + + var child, previous; + + // If there is no range then get out of here. + // It happens on initial load in Safari #962 and if the editor it's + // hidden also in Firefox + if ( !startContainer || !endContainer ) + return { start : 0, end : 0 }; + + if ( normalized ) + { + // Find out if the start is pointing to a text node that will + // be normalized. + if ( startContainer.type == CKEDITOR.NODE_ELEMENT ) + { + child = startContainer.getChild( startOffset ); + + // In this case, move the start information to that text + // node. + if ( child && child.type == CKEDITOR.NODE_TEXT + && startOffset > 0 && child.getPrevious().type == CKEDITOR.NODE_TEXT ) + { + startContainer = child; + startOffset = 0; + } + + // Get the normalized offset. + if ( child && child.type == CKEDITOR.NODE_ELEMENT ) + startOffset = child.getIndex( 1 ); + } + + // Normalize the start. + while ( startContainer.type == CKEDITOR.NODE_TEXT + && ( previous = startContainer.getPrevious() ) + && previous.type == CKEDITOR.NODE_TEXT ) + { + startContainer = previous; + startOffset += previous.getLength(); + } + + // Process the end only if not normalized. + if ( !collapsed ) + { + // Find out if the start is pointing to a text node that + // will be normalized. + if ( endContainer.type == CKEDITOR.NODE_ELEMENT ) + { + child = endContainer.getChild( endOffset ); + + // In this case, move the start information to that + // text node. + if ( child && child.type == CKEDITOR.NODE_TEXT + && endOffset > 0 && child.getPrevious().type == CKEDITOR.NODE_TEXT ) + { + endContainer = child; + endOffset = 0; + } + + // Get the normalized offset. + if ( child && child.type == CKEDITOR.NODE_ELEMENT ) + endOffset = child.getIndex( 1 ); + } + + // Normalize the end. + while ( endContainer.type == CKEDITOR.NODE_TEXT + && ( previous = endContainer.getPrevious() ) + && previous.type == CKEDITOR.NODE_TEXT ) + { + endContainer = previous; + endOffset += previous.getLength(); + } + } + } + + return { + start : startContainer.getAddress( normalized ), + end : collapsed ? null : endContainer.getAddress( normalized ), + startOffset : startOffset, + endOffset : endOffset, + normalized : normalized, + collapsed : collapsed, + is2 : true // It's a createBookmark2 bookmark. + }; + }, + + moveToBookmark : function( bookmark ) + { + if ( bookmark.is2 ) // Created with createBookmark2(). + { + // Get the start information. + var startContainer = this.document.getByAddress( bookmark.start, bookmark.normalized ), + startOffset = bookmark.startOffset; + + // Get the end information. + var endContainer = bookmark.end && this.document.getByAddress( bookmark.end, bookmark.normalized ), + endOffset = bookmark.endOffset; + + // Set the start boundary. + this.setStart( startContainer, startOffset ); + + // Set the end boundary. If not available, collapse it. + if ( endContainer ) + this.setEnd( endContainer, endOffset ); + else + this.collapse( true ); + } + else // Created with createBookmark(). + { + var serializable = bookmark.serializable, + startNode = serializable ? this.document.getById( bookmark.startNode ) : bookmark.startNode, + endNode = serializable ? this.document.getById( bookmark.endNode ) : bookmark.endNode; + + // Set the range start at the bookmark start node position. + this.setStartBefore( startNode ); + + // Remove it, because it may interfere in the setEndBefore call. + startNode.remove(); + + // Set the range end at the bookmark end node position, or simply + // collapse it if it is not available. + if ( endNode ) + { + this.setEndBefore( endNode ); + endNode.remove(); + } + else + this.collapse( true ); + } + }, + + getBoundaryNodes : function() + { + var startNode = this.startContainer, + endNode = this.endContainer, + startOffset = this.startOffset, + endOffset = this.endOffset, + childCount; + + if ( startNode.type == CKEDITOR.NODE_ELEMENT ) + { + childCount = startNode.getChildCount(); + if ( childCount > startOffset ) + startNode = startNode.getChild( startOffset ); + else if ( childCount < 1 ) + startNode = startNode.getPreviousSourceNode(); + else // startOffset > childCount but childCount is not 0 + { + // Try to take the node just after the current position. + startNode = startNode.$; + while ( startNode.lastChild ) + startNode = startNode.lastChild; + startNode = new CKEDITOR.dom.node( startNode ); + + // Normally we should take the next node in DFS order. But it + // is also possible that we've already reached the end of + // document. + startNode = startNode.getNextSourceNode() || startNode; + } + } + if ( endNode.type == CKEDITOR.NODE_ELEMENT ) + { + childCount = endNode.getChildCount(); + if ( childCount > endOffset ) + endNode = endNode.getChild( endOffset ).getPreviousSourceNode( true ); + else if ( childCount < 1 ) + endNode = endNode.getPreviousSourceNode(); + else // endOffset > childCount but childCount is not 0 + { + // Try to take the node just before the current position. + endNode = endNode.$; + while ( endNode.lastChild ) + endNode = endNode.lastChild; + endNode = new CKEDITOR.dom.node( endNode ); + } + } + + // Sometimes the endNode will come right before startNode for collapsed + // ranges. Fix it. (#3780) + if ( startNode.getPosition( endNode ) & CKEDITOR.POSITION_FOLLOWING ) + startNode = endNode; + + return { startNode : startNode, endNode : endNode }; + }, + + /** + * Find the node which fully contains the range. + * @param includeSelf + * @param {Boolean} ignoreTextNode Whether ignore CKEDITOR.NODE_TEXT type. + */ + getCommonAncestor : function( includeSelf , ignoreTextNode ) + { + var start = this.startContainer, + end = this.endContainer, + ancestor; + + if ( start.equals( end ) ) + { + if ( includeSelf + && start.type == CKEDITOR.NODE_ELEMENT + && this.startOffset == this.endOffset - 1 ) + ancestor = start.getChild( this.startOffset ); + else + ancestor = start; + } + else + ancestor = start.getCommonAncestor( end ); + + return ignoreTextNode && !ancestor.is ? ancestor.getParent() : ancestor; + }, + + /** + * Transforms the startContainer and endContainer properties from text + * nodes to element nodes, whenever possible. This is actually possible + * if either of the boundary containers point to a text node, and its + * offset is set to zero, or after the last char in the node. + */ + optimize : function() + { + var container = this.startContainer; + var offset = this.startOffset; + + if ( container.type != CKEDITOR.NODE_ELEMENT ) + { + if ( !offset ) + this.setStartBefore( container ); + else if ( offset >= container.getLength() ) + this.setStartAfter( container ); + } + + container = this.endContainer; + offset = this.endOffset; + + if ( container.type != CKEDITOR.NODE_ELEMENT ) + { + if ( !offset ) + this.setEndBefore( container ); + else if ( offset >= container.getLength() ) + this.setEndAfter( container ); + } + }, + + /** + * Move the range out of bookmark nodes if they'd been the container. + */ + optimizeBookmark: function() + { + var startNode = this.startContainer, + endNode = this.endContainer; + + if ( startNode.is && startNode.is( 'span' ) + && startNode.data( 'cke-bookmark' ) ) + this.setStartAt( startNode, CKEDITOR.POSITION_BEFORE_START ); + if ( endNode && endNode.is && endNode.is( 'span' ) + && endNode.data( 'cke-bookmark' ) ) + this.setEndAt( endNode, CKEDITOR.POSITION_AFTER_END ); + }, + + trim : function( ignoreStart, ignoreEnd ) + { + var startContainer = this.startContainer, + startOffset = this.startOffset, + collapsed = this.collapsed; + if ( ( !ignoreStart || collapsed ) + && startContainer && startContainer.type == CKEDITOR.NODE_TEXT ) + { + // If the offset is zero, we just insert the new node before + // the start. + if ( !startOffset ) + { + startOffset = startContainer.getIndex(); + startContainer = startContainer.getParent(); + } + // If the offset is at the end, we'll insert it after the text + // node. + else if ( startOffset >= startContainer.getLength() ) + { + startOffset = startContainer.getIndex() + 1; + startContainer = startContainer.getParent(); + } + // In other case, we split the text node and insert the new + // node at the split point. + else + { + var nextText = startContainer.split( startOffset ); + + startOffset = startContainer.getIndex() + 1; + startContainer = startContainer.getParent(); + + // Check all necessity of updating the end boundary. + if ( this.startContainer.equals( this.endContainer ) ) + this.setEnd( nextText, this.endOffset - this.startOffset ); + else if ( startContainer.equals( this.endContainer ) ) + this.endOffset += 1; + } + + this.setStart( startContainer, startOffset ); + + if ( collapsed ) + { + this.collapse( true ); + return; + } + } + + var endContainer = this.endContainer; + var endOffset = this.endOffset; + + if ( !( ignoreEnd || collapsed ) + && endContainer && endContainer.type == CKEDITOR.NODE_TEXT ) + { + // If the offset is zero, we just insert the new node before + // the start. + if ( !endOffset ) + { + endOffset = endContainer.getIndex(); + endContainer = endContainer.getParent(); + } + // If the offset is at the end, we'll insert it after the text + // node. + else if ( endOffset >= endContainer.getLength() ) + { + endOffset = endContainer.getIndex() + 1; + endContainer = endContainer.getParent(); + } + // In other case, we split the text node and insert the new + // node at the split point. + else + { + endContainer.split( endOffset ); + + endOffset = endContainer.getIndex() + 1; + endContainer = endContainer.getParent(); + } + + this.setEnd( endContainer, endOffset ); + } + }, + + /** + * Expands the range so that partial units are completely contained. + * @param unit {Number} The unit type to expand with. + * @param {Boolean} [excludeBrs=false] Whether include line-breaks when expanding. + */ + enlarge : function( unit, excludeBrs ) + { + switch ( unit ) + { + case CKEDITOR.ENLARGE_ELEMENT : + + if ( this.collapsed ) + return; + + // Get the common ancestor. + var commonAncestor = this.getCommonAncestor(); + + var body = this.document.getBody(); + + // For each boundary + // a. Depending on its position, find out the first node to be checked (a sibling) or, if not available, to be enlarge. + // b. Go ahead checking siblings and enlarging the boundary as much as possible until the common ancestor is not reached. After reaching the common ancestor, just save the enlargeable node to be used later. + + var startTop, endTop; + + var enlargeable, sibling, commonReached; + + // Indicates that the node can be added only if whitespace + // is available before it. + var needsWhiteSpace = false; + var isWhiteSpace; + var siblingText; + + // Process the start boundary. + + var container = this.startContainer; + var offset = this.startOffset; + + if ( container.type == CKEDITOR.NODE_TEXT ) + { + if ( offset ) + { + // Check if there is any non-space text before the + // offset. Otherwise, container is null. + container = !CKEDITOR.tools.trim( container.substring( 0, offset ) ).length && container; + + // If we found only whitespace in the node, it + // means that we'll need more whitespace to be able + // to expand. For example, can be expanded in + // "A [B]", but not in "A [B]". + needsWhiteSpace = !!container; + } + + if ( container ) + { + if ( !( sibling = container.getPrevious() ) ) + enlargeable = container.getParent(); + } + } + else + { + // If we have offset, get the node preceeding it as the + // first sibling to be checked. + if ( offset ) + sibling = container.getChild( offset - 1 ) || container.getLast(); + + // If there is no sibling, mark the container to be + // enlarged. + if ( !sibling ) + enlargeable = container; + } + + while ( enlargeable || sibling ) + { + if ( enlargeable && !sibling ) + { + // If we reached the common ancestor, mark the flag + // for it. + if ( !commonReached && enlargeable.equals( commonAncestor ) ) + commonReached = true; + + if ( !body.contains( enlargeable ) ) + break; + + // If we don't need space or this element breaks + // the line, then enlarge it. + if ( !needsWhiteSpace || enlargeable.getComputedStyle( 'display' ) != 'inline' ) + { + needsWhiteSpace = false; + + // If the common ancestor has been reached, + // we'll not enlarge it immediately, but just + // mark it to be enlarged later if the end + // boundary also enlarges it. + if ( commonReached ) + startTop = enlargeable; + else + this.setStartBefore( enlargeable ); + } + + sibling = enlargeable.getPrevious(); + } + + // Check all sibling nodes preceeding the enlargeable + // node. The node wil lbe enlarged only if none of them + // blocks it. + while ( sibling ) + { + // This flag indicates that this node has + // whitespaces at the end. + isWhiteSpace = false; + + if ( sibling.type == CKEDITOR.NODE_TEXT ) + { + siblingText = sibling.getText(); + + if ( /[^\s\ufeff]/.test( siblingText ) ) + sibling = null; + + isWhiteSpace = /[\s\ufeff]$/.test( siblingText ); + } + else + { + // If this is a visible element. + // We need to check for the bookmark attribute because IE insists on + // rendering the display:none nodes we use for bookmarks. (#3363) + // Line-breaks (br) are rendered with zero width, which we don't want to include. (#7041) + if ( ( sibling.$.offsetWidth > 0 || excludeBrs && sibling.is( 'br' ) ) && !sibling.data( 'cke-bookmark' ) ) + { + // We'll accept it only if we need + // whitespace, and this is an inline + // element with whitespace only. + if ( needsWhiteSpace && CKEDITOR.dtd.$removeEmpty[ sibling.getName() ] ) + { + // It must contains spaces and inline elements only. + + siblingText = sibling.getText(); + + if ( (/[^\s\ufeff]/).test( siblingText ) ) // Spaces + Zero Width No-Break Space (U+FEFF) + sibling = null; + else + { + var allChildren = sibling.$.all || sibling.$.getElementsByTagName( '*' ); + for ( var i = 0, child ; child = allChildren[ i++ ] ; ) + { + if ( !CKEDITOR.dtd.$removeEmpty[ child.nodeName.toLowerCase() ] ) + { + sibling = null; + break; + } + } + } + + if ( sibling ) + isWhiteSpace = !!siblingText.length; + } + else + sibling = null; + } + } + + // A node with whitespaces has been found. + if ( isWhiteSpace ) + { + // Enlarge the last enlargeable node, if we + // were waiting for spaces. + if ( needsWhiteSpace ) + { + if ( commonReached ) + startTop = enlargeable; + else if ( enlargeable ) + this.setStartBefore( enlargeable ); + } + else + needsWhiteSpace = true; + } + + if ( sibling ) + { + var next = sibling.getPrevious(); + + if ( !enlargeable && !next ) + { + // Set the sibling as enlargeable, so it's + // parent will be get later outside this while. + enlargeable = sibling; + sibling = null; + break; + } + + sibling = next; + } + else + { + // If sibling has been set to null, then we + // need to stop enlarging. + enlargeable = null; + } + } + + if ( enlargeable ) + enlargeable = enlargeable.getParent(); + } + + // Process the end boundary. This is basically the same + // code used for the start boundary, with small changes to + // make it work in the oposite side (to the right). This + // makes it difficult to reuse the code here. So, fixes to + // the above code are likely to be replicated here. + + container = this.endContainer; + offset = this.endOffset; + + // Reset the common variables. + enlargeable = sibling = null; + commonReached = needsWhiteSpace = false; + + if ( container.type == CKEDITOR.NODE_TEXT ) + { + // Check if there is any non-space text after the + // offset. Otherwise, container is null. + container = !CKEDITOR.tools.trim( container.substring( offset ) ).length && container; + + // If we found only whitespace in the node, it + // means that we'll need more whitespace to be able + // to expand. For example, can be expanded in + // "A [B]", but not in "A [B]". + needsWhiteSpace = !( container && container.getLength() ); + + if ( container ) + { + if ( !( sibling = container.getNext() ) ) + enlargeable = container.getParent(); + } + } + else + { + // Get the node right after the boudary to be checked + // first. + sibling = container.getChild( offset ); + + if ( !sibling ) + enlargeable = container; + } + + while ( enlargeable || sibling ) + { + if ( enlargeable && !sibling ) + { + if ( !commonReached && enlargeable.equals( commonAncestor ) ) + commonReached = true; + + if ( !body.contains( enlargeable ) ) + break; + + if ( !needsWhiteSpace || enlargeable.getComputedStyle( 'display' ) != 'inline' ) + { + needsWhiteSpace = false; + + if ( commonReached ) + endTop = enlargeable; + else if ( enlargeable ) + this.setEndAfter( enlargeable ); + } + + sibling = enlargeable.getNext(); + } + + while ( sibling ) + { + isWhiteSpace = false; + + if ( sibling.type == CKEDITOR.NODE_TEXT ) + { + siblingText = sibling.getText(); + + if ( /[^\s\ufeff]/.test( siblingText ) ) + sibling = null; + + isWhiteSpace = /^[\s\ufeff]/.test( siblingText ); + } + else + { + // If this is a visible element. + // We need to check for the bookmark attribute because IE insists on + // rendering the display:none nodes we use for bookmarks. (#3363) + // Line-breaks (br) are rendered with zero width, which we don't want to include. (#7041) + if ( ( sibling.$.offsetWidth > 0 || excludeBrs && sibling.is( 'br' ) ) && !sibling.data( 'cke-bookmark' ) ) + { + // We'll accept it only if we need + // whitespace, and this is an inline + // element with whitespace only. + if ( needsWhiteSpace && CKEDITOR.dtd.$removeEmpty[ sibling.getName() ] ) + { + // It must contains spaces and inline elements only. + + siblingText = sibling.getText(); + + if ( (/[^\s\ufeff]/).test( siblingText ) ) + sibling = null; + else + { + allChildren = sibling.$.all || sibling.$.getElementsByTagName( '*' ); + for ( i = 0 ; child = allChildren[ i++ ] ; ) + { + if ( !CKEDITOR.dtd.$removeEmpty[ child.nodeName.toLowerCase() ] ) + { + sibling = null; + break; + } + } + } + + if ( sibling ) + isWhiteSpace = !!siblingText.length; + } + else + sibling = null; + } + } + + if ( isWhiteSpace ) + { + if ( needsWhiteSpace ) + { + if ( commonReached ) + endTop = enlargeable; + else + this.setEndAfter( enlargeable ); + } + } + + if ( sibling ) + { + next = sibling.getNext(); + + if ( !enlargeable && !next ) + { + enlargeable = sibling; + sibling = null; + break; + } + + sibling = next; + } + else + { + // If sibling has been set to null, then we + // need to stop enlarging. + enlargeable = null; + } + } + + if ( enlargeable ) + enlargeable = enlargeable.getParent(); + } + + // If the common ancestor can be enlarged by both boundaries, then include it also. + if ( startTop && endTop ) + { + commonAncestor = startTop.contains( endTop ) ? endTop : startTop; + + this.setStartBefore( commonAncestor ); + this.setEndAfter( commonAncestor ); + } + break; + + case CKEDITOR.ENLARGE_BLOCK_CONTENTS: + case CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS: + + // Enlarging the start boundary. + var walkerRange = new CKEDITOR.dom.range( this.document ); + + body = this.document.getBody(); + + walkerRange.setStartAt( body, CKEDITOR.POSITION_AFTER_START ); + walkerRange.setEnd( this.startContainer, this.startOffset ); + + var walker = new CKEDITOR.dom.walker( walkerRange ), + blockBoundary, // The node on which the enlarging should stop. + tailBr, // In case BR as block boundary. + notBlockBoundary = CKEDITOR.dom.walker.blockBoundary( + ( unit == CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS ) ? { br : 1 } : null ), + // Record the encountered 'blockBoundary' for later use. + boundaryGuard = function( node ) + { + var retval = notBlockBoundary( node ); + if ( !retval ) + blockBoundary = node; + return retval; + }, + // Record the encounted 'tailBr' for later use. + tailBrGuard = function( node ) + { + var retval = boundaryGuard( node ); + if ( !retval && node.is && node.is( 'br' ) ) + tailBr = node; + return retval; + }; + + walker.guard = boundaryGuard; + + enlargeable = walker.lastBackward(); + + // It's the body which stop the enlarging if no block boundary found. + blockBoundary = blockBoundary || body; + + // Start the range either after the end of found block (

...

[text) + // or at the start of block (

[text...), by comparing the document position + // with 'enlargeable' node. + this.setStartAt( + blockBoundary, + !blockBoundary.is( 'br' ) && + ( !enlargeable && this.checkStartOfBlock() + || enlargeable && blockBoundary.contains( enlargeable ) ) ? + CKEDITOR.POSITION_AFTER_START : + CKEDITOR.POSITION_AFTER_END ); + + // Avoid enlarging the range further when end boundary spans right after the BR. (#7490) + if ( unit == CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS ) + { + var theRange = this.clone(); + walker = new CKEDITOR.dom.walker( theRange ); + + var whitespaces = CKEDITOR.dom.walker.whitespaces(), + bookmark = CKEDITOR.dom.walker.bookmark(); + + walker.evaluator = function( node ) { return !whitespaces( node ) && !bookmark( node ); }; + var previous = walker.previous(); + if ( previous && previous.type == CKEDITOR.NODE_ELEMENT && previous.is( 'br' ) ) + return; + } + + + // Enlarging the end boundary. + walkerRange = this.clone(); + walkerRange.collapse(); + walkerRange.setEndAt( body, CKEDITOR.POSITION_BEFORE_END ); + walker = new CKEDITOR.dom.walker( walkerRange ); + + // tailBrGuard only used for on range end. + walker.guard = ( unit == CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS ) ? + tailBrGuard : boundaryGuard; + blockBoundary = null; + // End the range right before the block boundary node. + + enlargeable = walker.lastForward(); + + // It's the body which stop the enlarging if no block boundary found. + blockBoundary = blockBoundary || body; + + // Close the range either before the found block start (text]

...

) or at the block end (...text]

) + // by comparing the document position with 'enlargeable' node. + this.setEndAt( + blockBoundary, + ( !enlargeable && this.checkEndOfBlock() + || enlargeable && blockBoundary.contains( enlargeable ) ) ? + CKEDITOR.POSITION_BEFORE_END : + CKEDITOR.POSITION_BEFORE_START ); + // We must include the
at the end of range if there's + // one and we're expanding list item contents + if ( tailBr ) + this.setEndAfter( tailBr ); + } + }, + + /** + * Descrease the range to make sure that boundaries + * always anchor beside text nodes or innermost element. + * @param {Number} mode ( CKEDITOR.SHRINK_ELEMENT | CKEDITOR.SHRINK_TEXT ) The shrinking mode. + *
+ *
CKEDITOR.SHRINK_ELEMENT
+ *
Shrink the range boundaries to the edge of the innermost element.
+ *
CKEDITOR.SHRINK_TEXT
+ *
Shrink the range boudaries to anchor by the side of enclosed text node, range remains if there's no text nodes on boundaries at all.
+ *
+ * @param {Boolean} selectContents Whether result range anchors at the inner OR outer boundary of the node. + */ + shrink : function( mode, selectContents ) + { + // Unable to shrink a collapsed range. + if ( !this.collapsed ) + { + mode = mode || CKEDITOR.SHRINK_TEXT; + + var walkerRange = this.clone(); + + var startContainer = this.startContainer, + endContainer = this.endContainer, + startOffset = this.startOffset, + endOffset = this.endOffset, + collapsed = this.collapsed; + + // Whether the start/end boundary is moveable. + var moveStart = 1, + moveEnd = 1; + + if ( startContainer && startContainer.type == CKEDITOR.NODE_TEXT ) + { + if ( !startOffset ) + walkerRange.setStartBefore( startContainer ); + else if ( startOffset >= startContainer.getLength( ) ) + walkerRange.setStartAfter( startContainer ); + else + { + // Enlarge the range properly to avoid walker making + // DOM changes caused by triming the text nodes later. + walkerRange.setStartBefore( startContainer ); + moveStart = 0; + } + } + + if ( endContainer && endContainer.type == CKEDITOR.NODE_TEXT ) + { + if ( !endOffset ) + walkerRange.setEndBefore( endContainer ); + else if ( endOffset >= endContainer.getLength( ) ) + walkerRange.setEndAfter( endContainer ); + else + { + walkerRange.setEndAfter( endContainer ); + moveEnd = 0; + } + } + + var walker = new CKEDITOR.dom.walker( walkerRange ), + isBookmark = CKEDITOR.dom.walker.bookmark(); + + walker.evaluator = function( node ) + { + return node.type == ( mode == CKEDITOR.SHRINK_ELEMENT ? + CKEDITOR.NODE_ELEMENT : CKEDITOR.NODE_TEXT ); + }; + + var currentElement; + walker.guard = function( node, movingOut ) + { + if ( isBookmark( node ) ) + return true; + + // Stop when we're shrink in element mode while encountering a text node. + if ( mode == CKEDITOR.SHRINK_ELEMENT && node.type == CKEDITOR.NODE_TEXT ) + return false; + + // Stop when we've already walked "through" an element. + if ( movingOut && node.equals( currentElement ) ) + return false; + + if ( !movingOut && node.type == CKEDITOR.NODE_ELEMENT ) + currentElement = node; + + return true; + }; + + if ( moveStart ) + { + var textStart = walker[ mode == CKEDITOR.SHRINK_ELEMENT ? 'lastForward' : 'next'](); + textStart && this.setStartAt( textStart, selectContents ? CKEDITOR.POSITION_AFTER_START : CKEDITOR.POSITION_BEFORE_START ); + } + + if ( moveEnd ) + { + walker.reset(); + var textEnd = walker[ mode == CKEDITOR.SHRINK_ELEMENT ? 'lastBackward' : 'previous'](); + textEnd && this.setEndAt( textEnd, selectContents ? CKEDITOR.POSITION_BEFORE_END : CKEDITOR.POSITION_AFTER_END ); + } + + return !!( moveStart || moveEnd ); + } + }, + + /** + * Inserts a node at the start of the range. The range will be expanded + * the contain the node. + */ + insertNode : function( node ) + { + this.optimizeBookmark(); + this.trim( false, true ); + + var startContainer = this.startContainer; + var startOffset = this.startOffset; + + var nextNode = startContainer.getChild( startOffset ); + + if ( nextNode ) + node.insertBefore( nextNode ); + else + startContainer.append( node ); + + // Check if we need to update the end boundary. + if ( node.getParent().equals( this.endContainer ) ) + this.endOffset++; + + // Expand the range to embrace the new node. + this.setStartBefore( node ); + }, + + moveToPosition : function( node, position ) + { + this.setStartAt( node, position ); + this.collapse( true ); + }, + + selectNodeContents : function( node ) + { + this.setStart( node, 0 ); + this.setEnd( node, node.type == CKEDITOR.NODE_TEXT ? node.getLength() : node.getChildCount() ); + }, + + /** + * Sets the start position of a Range. + * @param {CKEDITOR.dom.node} startNode The node to start the range. + * @param {Number} startOffset An integer greater than or equal to zero + * representing the offset for the start of the range from the start + * of startNode. + */ + setStart : function( startNode, startOffset ) + { + // W3C requires a check for the new position. If it is after the end + // boundary, the range should be collapsed to the new start. It seams + // we will not need this check for our use of this class so we can + // ignore it for now. + + // Fixing invalid range start inside dtd empty elements. + if( startNode.type == CKEDITOR.NODE_ELEMENT + && CKEDITOR.dtd.$empty[ startNode.getName() ] ) + startOffset = startNode.getIndex(), startNode = startNode.getParent(); + + this.startContainer = startNode; + this.startOffset = startOffset; + + if ( !this.endContainer ) + { + this.endContainer = startNode; + this.endOffset = startOffset; + } + + updateCollapsed( this ); + }, + + /** + * Sets the end position of a Range. + * @param {CKEDITOR.dom.node} endNode The node to end the range. + * @param {Number} endOffset An integer greater than or equal to zero + * representing the offset for the end of the range from the start + * of endNode. + */ + setEnd : function( endNode, endOffset ) + { + // W3C requires a check for the new position. If it is before the start + // boundary, the range should be collapsed to the new end. It seams we + // will not need this check for our use of this class so we can ignore + // it for now. + + // Fixing invalid range end inside dtd empty elements. + if( endNode.type == CKEDITOR.NODE_ELEMENT + && CKEDITOR.dtd.$empty[ endNode.getName() ] ) + endOffset = endNode.getIndex() + 1, endNode = endNode.getParent(); + + this.endContainer = endNode; + this.endOffset = endOffset; + + if ( !this.startContainer ) + { + this.startContainer = endNode; + this.startOffset = endOffset; + } + + updateCollapsed( this ); + }, + + setStartAfter : function( node ) + { + this.setStart( node.getParent(), node.getIndex() + 1 ); + }, + + setStartBefore : function( node ) + { + this.setStart( node.getParent(), node.getIndex() ); + }, + + setEndAfter : function( node ) + { + this.setEnd( node.getParent(), node.getIndex() + 1 ); + }, + + setEndBefore : function( node ) + { + this.setEnd( node.getParent(), node.getIndex() ); + }, + + setStartAt : function( node, position ) + { + switch( position ) + { + case CKEDITOR.POSITION_AFTER_START : + this.setStart( node, 0 ); + break; + + case CKEDITOR.POSITION_BEFORE_END : + if ( node.type == CKEDITOR.NODE_TEXT ) + this.setStart( node, node.getLength() ); + else + this.setStart( node, node.getChildCount() ); + break; + + case CKEDITOR.POSITION_BEFORE_START : + this.setStartBefore( node ); + break; + + case CKEDITOR.POSITION_AFTER_END : + this.setStartAfter( node ); + } + + updateCollapsed( this ); + }, + + setEndAt : function( node, position ) + { + switch( position ) + { + case CKEDITOR.POSITION_AFTER_START : + this.setEnd( node, 0 ); + break; + + case CKEDITOR.POSITION_BEFORE_END : + if ( node.type == CKEDITOR.NODE_TEXT ) + this.setEnd( node, node.getLength() ); + else + this.setEnd( node, node.getChildCount() ); + break; + + case CKEDITOR.POSITION_BEFORE_START : + this.setEndBefore( node ); + break; + + case CKEDITOR.POSITION_AFTER_END : + this.setEndAfter( node ); + } + + updateCollapsed( this ); + }, + + fixBlock : function( isStart, blockTag ) + { + var bookmark = this.createBookmark(), + fixedBlock = this.document.createElement( blockTag ); + + this.collapse( isStart ); + + this.enlarge( CKEDITOR.ENLARGE_BLOCK_CONTENTS ); + + this.extractContents().appendTo( fixedBlock ); + fixedBlock.trim(); + + if ( !CKEDITOR.env.ie ) + fixedBlock.appendBogus(); + + this.insertNode( fixedBlock ); + + this.moveToBookmark( bookmark ); + + return fixedBlock; + }, + + splitBlock : function( blockTag ) + { + var startPath = new CKEDITOR.dom.elementPath( this.startContainer ), + endPath = new CKEDITOR.dom.elementPath( this.endContainer ); + + var startBlockLimit = startPath.blockLimit, + endBlockLimit = endPath.blockLimit; + + var startBlock = startPath.block, + endBlock = endPath.block; + + var elementPath = null; + // Do nothing if the boundaries are in different block limits. + if ( !startBlockLimit.equals( endBlockLimit ) ) + return null; + + // Get or fix current blocks. + if ( blockTag != 'br' ) + { + if ( !startBlock ) + { + startBlock = this.fixBlock( true, blockTag ); + endBlock = new CKEDITOR.dom.elementPath( this.endContainer ).block; + } + + if ( !endBlock ) + endBlock = this.fixBlock( false, blockTag ); + } + + // Get the range position. + var isStartOfBlock = startBlock && this.checkStartOfBlock(), + isEndOfBlock = endBlock && this.checkEndOfBlock(); + + // Delete the current contents. + // TODO: Why is 2.x doing CheckIsEmpty()? + this.deleteContents(); + + if ( startBlock && startBlock.equals( endBlock ) ) + { + if ( isEndOfBlock ) + { + elementPath = new CKEDITOR.dom.elementPath( this.startContainer ); + this.moveToPosition( endBlock, CKEDITOR.POSITION_AFTER_END ); + endBlock = null; + } + else if ( isStartOfBlock ) + { + elementPath = new CKEDITOR.dom.elementPath( this.startContainer ); + this.moveToPosition( startBlock, CKEDITOR.POSITION_BEFORE_START ); + startBlock = null; + } + else + { + endBlock = this.splitElement( startBlock ); + + // In Gecko, the last child node must be a bogus
. + // Note: bogus
added under
    or
      would cause + // lists to be incorrectly rendered. + if ( !CKEDITOR.env.ie && !startBlock.is( 'ul', 'ol') ) + startBlock.appendBogus() ; + } + } + + return { + previousBlock : startBlock, + nextBlock : endBlock, + wasStartOfBlock : isStartOfBlock, + wasEndOfBlock : isEndOfBlock, + elementPath : elementPath + }; + }, + + /** + * Branch the specified element from the collapsed range position and + * place the caret between the two result branches. + * Note: The range must be collapsed and been enclosed by this element. + * @param {CKEDITOR.dom.element} element + * @return {CKEDITOR.dom.element} Root element of the new branch after the split. + */ + splitElement : function( toSplit ) + { + if ( !this.collapsed ) + return null; + + // Extract the contents of the block from the selection point to the end + // of its contents. + this.setEndAt( toSplit, CKEDITOR.POSITION_BEFORE_END ); + var documentFragment = this.extractContents(); + + // Duplicate the element after it. + var clone = toSplit.clone( false ); + + // Place the extracted contents into the duplicated element. + documentFragment.appendTo( clone ); + clone.insertAfter( toSplit ); + this.moveToPosition( toSplit, CKEDITOR.POSITION_AFTER_END ); + return clone; + }, + + /** + * Check whether a range boundary is at the inner boundary of a given + * element. + * @param {CKEDITOR.dom.element} element The target element to check. + * @param {Number} checkType The boundary to check for both the range + * and the element. It can be CKEDITOR.START or CKEDITOR.END. + * @returns {Boolean} "true" if the range boundary is at the inner + * boundary of the element. + */ + checkBoundaryOfElement : function( element, checkType ) + { + var checkStart = ( checkType == CKEDITOR.START ); + + // Create a copy of this range, so we can manipulate it for our checks. + var walkerRange = this.clone(); + + // Collapse the range at the proper size. + walkerRange.collapse( checkStart ); + + // Expand the range to element boundary. + walkerRange[ checkStart ? 'setStartAt' : 'setEndAt' ] + ( element, checkStart ? CKEDITOR.POSITION_AFTER_START : CKEDITOR.POSITION_BEFORE_END ); + + // Create the walker, which will check if we have anything useful + // in the range. + var walker = new CKEDITOR.dom.walker( walkerRange ); + walker.evaluator = elementBoundaryEval; + + return walker[ checkStart ? 'checkBackward' : 'checkForward' ](); + }, + + // Calls to this function may produce changes to the DOM. The range may + // be updated to reflect such changes. + checkStartOfBlock : function() + { + var startContainer = this.startContainer, + startOffset = this.startOffset; + + // If the starting node is a text node, and non-empty before the offset, + // then we're surely not at the start of block. + if ( startOffset && startContainer.type == CKEDITOR.NODE_TEXT ) + { + var textBefore = CKEDITOR.tools.ltrim( startContainer.substring( 0, startOffset ) ); + if ( textBefore.length ) + return false; + } + + // Antecipate the trim() call here, so the walker will not make + // changes to the DOM, which would not get reflected into this + // range otherwise. + this.trim(); + + // We need to grab the block element holding the start boundary, so + // let's use an element path for it. + var path = new CKEDITOR.dom.elementPath( this.startContainer ); + + // Creates a range starting at the block start until the range start. + var walkerRange = this.clone(); + walkerRange.collapse( true ); + walkerRange.setStartAt( path.block || path.blockLimit, CKEDITOR.POSITION_AFTER_START ); + + var walker = new CKEDITOR.dom.walker( walkerRange ); + walker.evaluator = getCheckStartEndBlockEvalFunction( true ); + + return walker.checkBackward(); + }, + + checkEndOfBlock : function() + { + var endContainer = this.endContainer, + endOffset = this.endOffset; + + // If the ending node is a text node, and non-empty after the offset, + // then we're surely not at the end of block. + if ( endContainer.type == CKEDITOR.NODE_TEXT ) + { + var textAfter = CKEDITOR.tools.rtrim( endContainer.substring( endOffset ) ); + if ( textAfter.length ) + return false; + } + + // Antecipate the trim() call here, so the walker will not make + // changes to the DOM, which would not get reflected into this + // range otherwise. + this.trim(); + + // We need to grab the block element holding the start boundary, so + // let's use an element path for it. + var path = new CKEDITOR.dom.elementPath( this.endContainer ); + + // Creates a range starting at the block start until the range start. + var walkerRange = this.clone(); + walkerRange.collapse( false ); + walkerRange.setEndAt( path.block || path.blockLimit, CKEDITOR.POSITION_BEFORE_END ); + + var walker = new CKEDITOR.dom.walker( walkerRange ); + walker.evaluator = getCheckStartEndBlockEvalFunction( false ); + + return walker.checkForward(); + }, + + /** + * Check if elements at which the range boundaries anchor are read-only, + * with respect to "contenteditable" attribute. + */ + checkReadOnly : ( function() + { + function checkNodesEditable( node, anotherEnd ) + { + while( node ) + { + if ( node.type == CKEDITOR.NODE_ELEMENT ) + { + if ( node.getAttribute( 'contentEditable' ) == 'false' + && !node.data( 'cke-editable' ) ) + { + return 0; + } + // Range enclosed entirely in an editable element. + else if ( node.is( 'html' ) + || node.getAttribute( 'contentEditable' ) == 'true' + && ( node.contains( anotherEnd ) || node.equals( anotherEnd ) ) ) + { + break; + } + } + node = node.getParent(); + } + + return 1; + } + + return function() + { + var startNode = this.startContainer, + endNode = this.endContainer; + + // Check if elements path at both boundaries are editable. + return !( checkNodesEditable( startNode, endNode ) && checkNodesEditable( endNode, startNode ) ); + }; + })(), + + /** + * Moves the range boundaries to the first/end editing point inside an + * element. For example, in an element tree like + * "<p><b><i></i></b> Text</p>", the start editing point is + * "<p><b><i>^</i></b> Text</p>" (inside <i>). + * @param {CKEDITOR.dom.element} el The element into which look for the + * editing spot. + * @param {Boolean} isMoveToEnd Whether move to the end editable position. + */ + moveToElementEditablePosition : function( el, isMoveToEnd ) + { + function nextDFS( node, childOnly ) + { + var next; + + if ( node.type == CKEDITOR.NODE_ELEMENT + && node.isEditable( false ) + && !CKEDITOR.dtd.$nonEditable[ node.getName() ] ) + { + next = node[ isMoveToEnd ? 'getLast' : 'getFirst' ]( nonWhitespaceOrBookmarkEval ); + } + + if ( !childOnly && !next ) + next = node[ isMoveToEnd ? 'getPrevious' : 'getNext' ]( nonWhitespaceOrBookmarkEval ); + + return next; + } + + var found = 0; + + while ( el ) + { + // Stop immediately if we've found a text node. + if ( el.type == CKEDITOR.NODE_TEXT ) + { + this.moveToPosition( el, isMoveToEnd ? + CKEDITOR.POSITION_AFTER_END : + CKEDITOR.POSITION_BEFORE_START ); + found = 1; + break; + } + + // If an editable element is found, move inside it, but not stop the searching. + if ( el.type == CKEDITOR.NODE_ELEMENT ) + { + if ( el.isEditable() ) + { + this.moveToPosition( el, isMoveToEnd ? + CKEDITOR.POSITION_BEFORE_END : + CKEDITOR.POSITION_AFTER_START ); + found = 1; + } + } + + el = nextDFS( el, found ); + } + + return !!found; + }, + + /** + *@see {CKEDITOR.dom.range.moveToElementEditablePosition} + */ + moveToElementEditStart : function( target ) + { + return this.moveToElementEditablePosition( target ); + }, + + /** + *@see {CKEDITOR.dom.range.moveToElementEditablePosition} + */ + moveToElementEditEnd : function( target ) + { + return this.moveToElementEditablePosition( target, true ); + }, + + /** + * Get the single node enclosed within the range if there's one. + */ + getEnclosedNode : function() + { + var walkerRange = this.clone(); + + // Optimize and analyze the range to avoid DOM destructive nature of walker. (#5780) + walkerRange.optimize(); + if ( walkerRange.startContainer.type != CKEDITOR.NODE_ELEMENT + || walkerRange.endContainer.type != CKEDITOR.NODE_ELEMENT ) + return null; + + var walker = new CKEDITOR.dom.walker( walkerRange ), + isNotBookmarks = CKEDITOR.dom.walker.bookmark( true ), + isNotWhitespaces = CKEDITOR.dom.walker.whitespaces( true ), + evaluator = function( node ) + { + return isNotWhitespaces( node ) && isNotBookmarks( node ); + }; + walkerRange.evaluator = evaluator; + var node = walker.next(); + walker.reset(); + return node && node.equals( walker.previous() ) ? node : null; + }, + + getTouchedStartNode : function() + { + var container = this.startContainer ; + + if ( this.collapsed || container.type != CKEDITOR.NODE_ELEMENT ) + return container ; + + return container.getChild( this.startOffset ) || container ; + }, + + getTouchedEndNode : function() + { + var container = this.endContainer ; + + if ( this.collapsed || container.type != CKEDITOR.NODE_ELEMENT ) + return container ; + + return container.getChild( this.endOffset - 1 ) || container ; + } + }; +})(); + +CKEDITOR.POSITION_AFTER_START = 1; // ^contents "^text" +CKEDITOR.POSITION_BEFORE_END = 2; // contents^ "text^" +CKEDITOR.POSITION_BEFORE_START = 3; // ^contents ^"text" +CKEDITOR.POSITION_AFTER_END = 4; // contents^ "text" + +CKEDITOR.ENLARGE_ELEMENT = 1; +CKEDITOR.ENLARGE_BLOCK_CONTENTS = 2; +CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS = 3; + +// Check boundary types. +// @see CKEDITOR.dom.range.prototype.checkBoundaryOfElement +CKEDITOR.START = 1; +CKEDITOR.END = 2; +CKEDITOR.STARTEND = 3; + +// Shrink range types. +// @see CKEDITOR.dom.range.prototype.shrink +CKEDITOR.SHRINK_ELEMENT = 1; +CKEDITOR.SHRINK_TEXT = 2; Index: 3rdParty_sources/ckeditor/core/dom/rangelist.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/core/dom/rangelist.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/core/dom/rangelist.js 17 Aug 2012 14:15:42 -0000 1.1 @@ -0,0 +1,213 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +(function() +{ + /** + * Represents a list os CKEDITOR.dom.range objects, which can be easily + * iterated sequentially. + * @constructor + * @param {CKEDITOR.dom.range|Array} [ranges] The ranges contained on this list. + * Note that, if an array of ranges is specified, the range sequence + * should match its DOM order. This class will not help to sort them. + */ + CKEDITOR.dom.rangeList = function( ranges ) + { + if ( ranges instanceof CKEDITOR.dom.rangeList ) + return ranges; + + if ( !ranges ) + ranges = []; + else if ( ranges instanceof CKEDITOR.dom.range ) + ranges = [ ranges ]; + + return CKEDITOR.tools.extend( ranges, mixins ); + }; + + var mixins = + /** @lends CKEDITOR.dom.rangeList.prototype */ + { + /** + * Creates an instance of the rangeList iterator, it should be used + * only when the ranges processing could be DOM intrusive, which + * means it may pollute and break other ranges in this list. + * Otherwise, it's enough to just iterate over this array in a for loop. + * @returns {CKEDITOR.dom.rangeListIterator} + */ + createIterator : function() + { + var rangeList = this, + bookmark = CKEDITOR.dom.walker.bookmark(), + guard = function( node ) { return ! ( node.is && node.is( 'tr' ) ); }, + bookmarks = [], + current; + + /** + * @lends CKEDITOR.dom.rangeListIterator.prototype + */ + return { + + /** + * Retrieves the next range in the list. + * @param {Boolean} mergeConsequent Whether join two adjacent ranges into single, e.g. consequent table cells. + */ + getNextRange : function( mergeConsequent ) + { + current = current == undefined ? 0 : current + 1; + + var range = rangeList[ current ]; + + // Multiple ranges might be mangled by each other. + if ( range && rangeList.length > 1 ) + { + // Bookmarking all other ranges on the first iteration, + // the range correctness after it doesn't matter since we'll + // restore them before the next iteration. + if ( !current ) + { + // Make sure bookmark correctness by reverse processing. + for ( var i = rangeList.length - 1; i >= 0; i-- ) + bookmarks.unshift( rangeList[ i ].createBookmark( true ) ); + } + + if ( mergeConsequent ) + { + // Figure out how many ranges should be merged. + var mergeCount = 0; + while ( rangeList[ current + mergeCount + 1 ] ) + { + var doc = range.document, + found = 0, + left = doc.getById( bookmarks[ mergeCount ].endNode ), + right = doc.getById( bookmarks[ mergeCount + 1 ].startNode ), + next; + + // Check subsequent range. + while ( 1 ) + { + next = left.getNextSourceNode( false ); + if ( !right.equals( next ) ) + { + // This could be yet another bookmark or + // walking across block boundaries. + if ( bookmark( next ) || ( next.type == CKEDITOR.NODE_ELEMENT && next.isBlockBoundary() ) ) + { + left = next; + continue; + } + } + else + found = 1; + + break; + } + + if ( !found ) + break; + + mergeCount++; + } + } + + range.moveToBookmark( bookmarks.shift() ); + + // Merge ranges finally after moving to bookmarks. + while( mergeCount-- ) + { + next = rangeList[ ++current ]; + next.moveToBookmark( bookmarks.shift() ); + range.setEnd( next.endContainer, next.endOffset ); + } + } + + return range; + } + }; + }, + + createBookmarks : function( serializable ) + { + var retval = [], bookmark; + for ( var i = 0; i < this.length ; i++ ) + { + retval.push( bookmark = this[ i ].createBookmark( serializable, true) ); + + // Updating the container & offset values for ranges + // that have been touched. + for ( var j = i + 1; j < this.length; j++ ) + { + this[ j ] = updateDirtyRange( bookmark, this[ j ] ); + this[ j ] = updateDirtyRange( bookmark, this[ j ], true ); + } + } + return retval; + }, + + createBookmarks2 : function( normalized ) + { + var bookmarks = []; + + for ( var i = 0 ; i < this.length ; i++ ) + bookmarks.push( this[ i ].createBookmark2( normalized ) ); + + return bookmarks; + }, + + /** + * Move each range in the list to the position specified by a list of bookmarks. + * @param {Array} bookmarks The list of bookmarks, each one matching a range in the list. + */ + moveToBookmarks : function( bookmarks ) + { + for ( var i = 0 ; i < this.length ; i++ ) + this[ i ].moveToBookmark( bookmarks[ i ] ); + } + }; + + // Update the specified range which has been mangled by previous insertion of + // range bookmark nodes.(#3256) + function updateDirtyRange( bookmark, dirtyRange, checkEnd ) + { + var serializable = bookmark.serializable, + container = dirtyRange[ checkEnd ? 'endContainer' : 'startContainer' ], + offset = checkEnd ? 'endOffset' : 'startOffset'; + + var bookmarkStart = serializable ? + dirtyRange.document.getById( bookmark.startNode ) + : bookmark.startNode; + + var bookmarkEnd = serializable ? + dirtyRange.document.getById( bookmark.endNode ) + : bookmark.endNode; + + if ( container.equals( bookmarkStart.getPrevious() ) ) + { + dirtyRange.startOffset = dirtyRange.startOffset + - container.getLength() + - bookmarkEnd.getPrevious().getLength(); + container = bookmarkEnd.getNext(); + } + else if ( container.equals( bookmarkEnd.getPrevious() ) ) + { + dirtyRange.startOffset = dirtyRange.startOffset - container.getLength(); + container = bookmarkEnd.getNext(); + } + + container.equals( bookmarkStart.getParent() ) && dirtyRange[ offset ]++; + container.equals( bookmarkEnd.getParent() ) && dirtyRange[ offset ]++; + + // Update and return this range. + dirtyRange[ checkEnd ? 'endContainer' : 'startContainer' ] = container; + return dirtyRange; + } +})(); + +/** + * (Virtual Class) Do not call this constructor. This class is not really part + * of the API. It just describes the return type of {@link CKEDITOR.dom.rangeList#createIterator}. + * @name CKEDITOR.dom.rangeListIterator + * @constructor + * @example + */ Index: 3rdParty_sources/ckeditor/core/dom/text.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/core/dom/text.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/core/dom/text.js 17 Aug 2012 14:15:42 -0000 1.1 @@ -0,0 +1,128 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * @fileOverview Defines the {@link CKEDITOR.dom.text} class, which represents + * a DOM text node. + */ + +/** + * Represents a DOM text node. + * @constructor + * @augments CKEDITOR.dom.node + * @param {Object|String} text A native DOM text node or a string containing + * the text to use to create a new text node. + * @param {CKEDITOR.dom.document} [ownerDocument] The document that will contain + * the node in case of new node creation. Defaults to the current document. + * @example + * var nativeNode = document.createTextNode( 'Example' ); + * var text = CKEDITOR.dom.text( nativeNode ); + * @example + * var text = CKEDITOR.dom.text( 'Example' ); + */ +CKEDITOR.dom.text = function( text, ownerDocument ) +{ + if ( typeof text == 'string' ) + text = ( ownerDocument ? ownerDocument.$ : document ).createTextNode( text ); + + // Theoretically, we should call the base constructor here + // (not CKEDITOR.dom.node though). But, IE doesn't support expando + // properties on text node, so the features provided by domObject will not + // work for text nodes (which is not a big issue for us). + // + // CKEDITOR.dom.domObject.call( this, element ); + + /** + * The native DOM text node represented by this class instance. + * @type Object + * @example + * var element = new CKEDITOR.dom.text( 'Example' ); + * alert( element.$.nodeType ); // "3" + */ + this.$ = text; +}; + +CKEDITOR.dom.text.prototype = new CKEDITOR.dom.node(); + +CKEDITOR.tools.extend( CKEDITOR.dom.text.prototype, + /** @lends CKEDITOR.dom.text.prototype */ + { + /** + * The node type. This is a constant value set to + * {@link CKEDITOR.NODE_TEXT}. + * @type Number + * @example + */ + type : CKEDITOR.NODE_TEXT, + + getLength : function() + { + return this.$.nodeValue.length; + }, + + getText : function() + { + return this.$.nodeValue; + }, + + setText : function( text ) + { + this.$.nodeValue = text; + }, + + /** + * Breaks this text node into two nodes at the specified offset, + * keeping both in the tree as siblings. This node then only contains + * all the content up to the offset point. A new text node, which is + * inserted as the next sibling of this node, contains all the content + * at and after the offset point. When the offset is equal to the + * length of this node, the new node has no data. + * @param {Number} The position at which to split, starting from zero. + * @returns {CKEDITOR.dom.text} The new text node. + */ + split : function( offset ) + { + // If the offset is after the last char, IE creates the text node + // on split, but don't include it into the DOM. So, we have to do + // that manually here. + if ( CKEDITOR.env.ie && offset == this.getLength() ) + { + var next = this.getDocument().createText( '' ); + next.insertAfter( this ); + return next; + } + + var doc = this.getDocument(); + var retval = new CKEDITOR.dom.text( this.$.splitText( offset ), doc ); + + // IE BUG: IE8 does not update the childNodes array in DOM after splitText(), + // we need to make some DOM changes to make it update. (#3436) + if ( CKEDITOR.env.ie8 ) + { + var workaround = new CKEDITOR.dom.text( '', doc ); + workaround.insertAfter( retval ); + workaround.remove(); + } + + return retval; + }, + + /** + * Extracts characters from indexA up to but not including indexB. + * @param {Number} indexA An integer between 0 and one less than the + * length of the text. + * @param {Number} [indexB] An integer between 0 and the length of the + * string. If omitted, extracts characters to the end of the text. + */ + substring : function( indexA, indexB ) + { + // We need the following check due to a Firefox bug + // https://bugzilla.mozilla.org/show_bug.cgi?id=458886 + if ( typeof indexB != 'number' ) + return this.$.nodeValue.substr( indexA ); + else + return this.$.nodeValue.substring( indexA, indexB ); + } + }); Index: 3rdParty_sources/ckeditor/core/dom/walker.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/core/dom/walker.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/core/dom/walker.js 17 Aug 2012 14:15:43 -0000 1.1 @@ -0,0 +1,462 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +(function() +{ + // This function is to be called under a "walker" instance scope. + function iterate( rtl, breakOnFalse ) + { + // Return null if we have reached the end. + if ( this._.end ) + return null; + + var node, + range = this.range, + guard, + userGuard = this.guard, + type = this.type, + getSourceNodeFn = ( rtl ? 'getPreviousSourceNode' : 'getNextSourceNode' ); + + // This is the first call. Initialize it. + if ( !this._.start ) + { + this._.start = 1; + + // Trim text nodes and optmize the range boundaries. DOM changes + // may happen at this point. + range.trim(); + + // A collapsed range must return null at first call. + if ( range.collapsed ) + { + this.end(); + return null; + } + } + + // Create the LTR guard function, if necessary. + if ( !rtl && !this._.guardLTR ) + { + // Gets the node that stops the walker when going LTR. + var limitLTR = range.endContainer, + blockerLTR = limitLTR.getChild( range.endOffset ); + + this._.guardLTR = function( node, movingOut ) + { + return ( ( !movingOut || !limitLTR.equals( node ) ) + && ( !blockerLTR || !node.equals( blockerLTR ) ) + && ( node.type != CKEDITOR.NODE_ELEMENT || !movingOut || node.getName() != 'body' ) ); + }; + } + + // Create the RTL guard function, if necessary. + if ( rtl && !this._.guardRTL ) + { + // Gets the node that stops the walker when going LTR. + var limitRTL = range.startContainer, + blockerRTL = ( range.startOffset > 0 ) && limitRTL.getChild( range.startOffset - 1 ); + + this._.guardRTL = function( node, movingOut ) + { + return ( ( !movingOut || !limitRTL.equals( node ) ) + && ( !blockerRTL || !node.equals( blockerRTL ) ) + && ( node.type != CKEDITOR.NODE_ELEMENT || !movingOut || node.getName() != 'body' ) ); + }; + } + + // Define which guard function to use. + var stopGuard = rtl ? this._.guardRTL : this._.guardLTR; + + // Make the user defined guard function participate in the process, + // otherwise simply use the boundary guard. + if ( userGuard ) + { + guard = function( node, movingOut ) + { + if ( stopGuard( node, movingOut ) === false ) + return false; + + return userGuard( node, movingOut ); + }; + } + else + guard = stopGuard; + + if ( this.current ) + node = this.current[ getSourceNodeFn ]( false, type, guard ); + else + { + // Get the first node to be returned. + + if ( rtl ) + { + node = range.endContainer; + + if ( range.endOffset > 0 ) + { + node = node.getChild( range.endOffset - 1 ); + if ( guard( node ) === false ) + node = null; + } + else + node = ( guard ( node, true ) === false ) ? + null : node.getPreviousSourceNode( true, type, guard ); + } + else + { + node = range.startContainer; + node = node.getChild( range.startOffset ); + + if ( node ) + { + if ( guard( node ) === false ) + node = null; + } + else + node = ( guard ( range.startContainer, true ) === false ) ? + null : range.startContainer.getNextSourceNode( true, type, guard ) ; + } + } + + while ( node && !this._.end ) + { + this.current = node; + + if ( !this.evaluator || this.evaluator( node ) !== false ) + { + if ( !breakOnFalse ) + return node; + } + else if ( breakOnFalse && this.evaluator ) + return false; + + node = node[ getSourceNodeFn ]( false, type, guard ); + } + + this.end(); + return this.current = null; + } + + function iterateToLast( rtl ) + { + var node, last = null; + + while ( ( node = iterate.call( this, rtl ) ) ) + last = node; + + return last; + } + + CKEDITOR.dom.walker = CKEDITOR.tools.createClass( + { + /** + * Utility class to "walk" the DOM inside a range boundaries. If + * necessary, partially included nodes (text nodes) are broken to + * reflect the boundaries limits, so DOM and range changes may happen. + * Outside changes to the range may break the walker. + * + * The walker may return nodes that are not totaly included into the + * range boundaires. Let's take the following range representation, + * where the square brackets indicate the boundaries: + * + * [<p>Some <b>sample] text</b> + * + * While walking forward into the above range, the following nodes are + * returned: <p>, "Some ", <b> and "sample". Going + * backwards instead we have: "sample" and "Some ". So note that the + * walker always returns nodes when "entering" them, but not when + * "leaving" them. The guard function is instead called both when + * entering and leaving nodes. + * + * @constructor + * @param {CKEDITOR.dom.range} range The range within which walk. + */ + $ : function( range ) + { + this.range = range; + + /** + * A function executed for every matched node, to check whether + * it's to be considered into the walk or not. If not provided, all + * matched nodes are considered good. + * If the function returns "false" the node is ignored. + * @name CKEDITOR.dom.walker.prototype.evaluator + * @property + * @type Function + */ + // this.evaluator = null; + + /** + * A function executed for every node the walk pass by to check + * whether the walk is to be finished. It's called when both + * entering and exiting nodes, as well as for the matched nodes. + * If this function returns "false", the walking ends and no more + * nodes are evaluated. + * @name CKEDITOR.dom.walker.prototype.guard + * @property + * @type Function + */ + // this.guard = null; + + /** @private */ + this._ = {}; + }, + +// statics : +// { +// /* Creates a CKEDITOR.dom.walker instance to walk inside DOM boundaries set by nodes. +// * @param {CKEDITOR.dom.node} startNode The node from wich the walk +// * will start. +// * @param {CKEDITOR.dom.node} [endNode] The last node to be considered +// * in the walk. No more nodes are retrieved after touching or +// * passing it. If not provided, the walker stops at the +// * <body> closing boundary. +// * @returns {CKEDITOR.dom.walker} A DOM walker for the nodes between the +// * provided nodes. +// */ +// createOnNodes : function( startNode, endNode, startInclusive, endInclusive ) +// { +// var range = new CKEDITOR.dom.range(); +// if ( startNode ) +// range.setStartAt( startNode, startInclusive ? CKEDITOR.POSITION_BEFORE_START : CKEDITOR.POSITION_AFTER_END ) ; +// else +// range.setStartAt( startNode.getDocument().getBody(), CKEDITOR.POSITION_AFTER_START ) ; +// +// if ( endNode ) +// range.setEndAt( endNode, endInclusive ? CKEDITOR.POSITION_AFTER_END : CKEDITOR.POSITION_BEFORE_START ) ; +// else +// range.setEndAt( startNode.getDocument().getBody(), CKEDITOR.POSITION_BEFORE_END ) ; +// +// return new CKEDITOR.dom.walker( range ); +// } +// }, +// + proto : + { + /** + * Stop walking. No more nodes are retrieved if this function gets + * called. + */ + end : function() + { + this._.end = 1; + }, + + /** + * Retrieves the next node (at right). + * @returns {CKEDITOR.dom.node} The next node or null if no more + * nodes are available. + */ + next : function() + { + return iterate.call( this ); + }, + + /** + * Retrieves the previous node (at left). + * @returns {CKEDITOR.dom.node} The previous node or null if no more + * nodes are available. + */ + previous : function() + { + return iterate.call( this, 1 ); + }, + + /** + * Check all nodes at right, executing the evaluation fuction. + * @returns {Boolean} "false" if the evaluator function returned + * "false" for any of the matched nodes. Otherwise "true". + */ + checkForward : function() + { + return iterate.call( this, 0, 1 ) !== false; + }, + + /** + * Check all nodes at left, executing the evaluation fuction. + * @returns {Boolean} "false" if the evaluator function returned + * "false" for any of the matched nodes. Otherwise "true". + */ + checkBackward : function() + { + return iterate.call( this, 1, 1 ) !== false; + }, + + /** + * Executes a full walk forward (to the right), until no more nodes + * are available, returning the last valid node. + * @returns {CKEDITOR.dom.node} The last node at the right or null + * if no valid nodes are available. + */ + lastForward : function() + { + return iterateToLast.call( this ); + }, + + /** + * Executes a full walk backwards (to the left), until no more nodes + * are available, returning the last valid node. + * @returns {CKEDITOR.dom.node} The last node at the left or null + * if no valid nodes are available. + */ + lastBackward : function() + { + return iterateToLast.call( this, 1 ); + }, + + reset : function() + { + delete this.current; + this._ = {}; + } + + } + }); + + /* + * Anything whose display computed style is block, list-item, table, + * table-row-group, table-header-group, table-footer-group, table-row, + * table-column-group, table-column, table-cell, table-caption, or whose node + * name is hr, br (when enterMode is br only) is a block boundary. + */ + var blockBoundaryDisplayMatch = + { + block : 1, + 'list-item' : 1, + table : 1, + 'table-row-group' : 1, + 'table-header-group' : 1, + 'table-footer-group' : 1, + 'table-row' : 1, + 'table-column-group' : 1, + 'table-column' : 1, + 'table-cell' : 1, + 'table-caption' : 1 + }; + + CKEDITOR.dom.element.prototype.isBlockBoundary = function( customNodeNames ) + { + var nodeNameMatches = customNodeNames ? + CKEDITOR.tools.extend( {}, CKEDITOR.dtd.$block, customNodeNames || {} ) : + CKEDITOR.dtd.$block; + + // Don't consider floated formatting as block boundary, fall back to dtd check in that case. (#6297) + return this.getComputedStyle( 'float' ) == 'none' && blockBoundaryDisplayMatch[ this.getComputedStyle( 'display' ) ] + || nodeNameMatches[ this.getName() ]; + }; + + CKEDITOR.dom.walker.blockBoundary = function( customNodeNames ) + { + return function( node , type ) + { + return ! ( node.type == CKEDITOR.NODE_ELEMENT + && node.isBlockBoundary( customNodeNames ) ); + }; + }; + + CKEDITOR.dom.walker.listItemBoundary = function() + { + return this.blockBoundary( { br : 1 } ); + }; + + /** + * Whether the to-be-evaluated node is a bookmark node OR bookmark node + * inner contents. + * @param {Boolean} contentOnly Whether only test againt the text content of + * bookmark node instead of the element itself(default). + * @param {Boolean} isReject Whether should return 'false' for the bookmark + * node instead of 'true'(default). + */ + CKEDITOR.dom.walker.bookmark = function( contentOnly, isReject ) + { + function isBookmarkNode( node ) + { + return ( node && node.getName + && node.getName() == 'span' + && node.data( 'cke-bookmark' ) ); + } + + return function( node ) + { + var isBookmark, parent; + // Is bookmark inner text node? + isBookmark = ( node && !node.getName && ( parent = node.getParent() ) + && isBookmarkNode( parent ) ); + // Is bookmark node? + isBookmark = contentOnly ? isBookmark : isBookmark || isBookmarkNode( node ); + return !! ( isReject ^ isBookmark ); + }; + }; + + /** + * Whether the node is a text node containing only whitespaces characters. + * @param isReject + */ + CKEDITOR.dom.walker.whitespaces = function( isReject ) + { + return function( node ) + { + var isWhitespace = node && ( node.type == CKEDITOR.NODE_TEXT ) + && !CKEDITOR.tools.trim( node.getText() ); + return !! ( isReject ^ isWhitespace ); + }; + }; + + /** + * Whether the node is invisible in wysiwyg mode. + * @param isReject + */ + CKEDITOR.dom.walker.invisible = function( isReject ) + { + var whitespace = CKEDITOR.dom.walker.whitespaces(); + return function( node ) + { + // Nodes that take no spaces in wysiwyg: + // 1. White-spaces but not including NBSP; + // 2. Empty inline elements, e.g. we're checking here + // 'offsetHeight' instead of 'offsetWidth' for properly excluding + // all sorts of empty paragraph, e.g.
      . + var isInvisible = whitespace( node ) || node.is && !node.$.offsetHeight; + return !! ( isReject ^ isInvisible ); + }; + }; + + CKEDITOR.dom.walker.nodeType = function( type, isReject ) + { + return function( node ) + { + return !! ( isReject ^ ( node.type == type ) ); + }; + }; + + var tailNbspRegex = /^[\t\r\n ]*(?: |\xa0)$/, + isWhitespaces = CKEDITOR.dom.walker.whitespaces(), + isBookmark = CKEDITOR.dom.walker.bookmark(), + toSkip = function( node ) + { + return isBookmark( node ) + || isWhitespaces( node ) + || node.type == CKEDITOR.NODE_ELEMENT + && node.getName() in CKEDITOR.dtd.$inline + && !( node.getName() in CKEDITOR.dtd.$empty ); + }; + + // Check if there's a filler node at the end of an element, and return it. + CKEDITOR.dom.element.prototype.getBogus = function() + { + // Bogus are not always at the end, e.g.

      text

      (#7070). + var tail = this; + do { tail = tail.getPreviousSourceNode(); } + while ( toSkip( tail ) ) + + if ( tail && ( !CKEDITOR.env.ie ? tail.is && tail.is( 'br' ) + : tail.getText && tailNbspRegex.test( tail.getText() ) ) ) + { + return tail; + } + return false; + }; + +})(); Index: 3rdParty_sources/ckeditor/core/dom/window.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/core/dom/window.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/core/dom/window.js 17 Aug 2012 14:15:42 -0000 1.1 @@ -0,0 +1,96 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * @fileOverview Defines the {@link CKEDITOR.dom.document} class, which + * represents a DOM document. + */ + +/** + * Represents a DOM window. + * @constructor + * @augments CKEDITOR.dom.domObject + * @param {Object} domWindow A native DOM window. + * @example + * var document = new CKEDITOR.dom.window( window ); + */ +CKEDITOR.dom.window = function( domWindow ) +{ + CKEDITOR.dom.domObject.call( this, domWindow ); +}; + +CKEDITOR.dom.window.prototype = new CKEDITOR.dom.domObject(); + +CKEDITOR.tools.extend( CKEDITOR.dom.window.prototype, + /** @lends CKEDITOR.dom.window.prototype */ + { + /** + * Moves the selection focus to this window. + * @function + * @example + * var win = new CKEDITOR.dom.window( window ); + * win.focus(); + */ + focus : function() + { + // Webkit is sometimes failed to focus iframe, blur it first(#3835). + if ( CKEDITOR.env.webkit && this.$.parent ) + this.$.parent.focus(); + this.$.focus(); + }, + + /** + * Gets the width and height of this window's viewable area. + * @function + * @returns {Object} An object with the "width" and "height" + * properties containing the size. + * @example + * var win = new CKEDITOR.dom.window( window ); + * var size = win.getViewPaneSize(); + * alert( size.width ); + * alert( size.height ); + */ + getViewPaneSize : function() + { + var doc = this.$.document, + stdMode = doc.compatMode == 'CSS1Compat'; + return { + width : ( stdMode ? doc.documentElement.clientWidth : doc.body.clientWidth ) || 0, + height : ( stdMode ? doc.documentElement.clientHeight : doc.body.clientHeight ) || 0 + }; + }, + + /** + * Gets the current position of the window's scroll. + * @function + * @returns {Object} An object with the "x" and "y" properties + * containing the scroll position. + * @example + * var win = new CKEDITOR.dom.window( window ); + * var pos = win.getScrollPosition(); + * alert( pos.x ); + * alert( pos.y ); + */ + getScrollPosition : function() + { + var $ = this.$; + + if ( 'pageXOffset' in $ ) + { + return { + x : $.pageXOffset || 0, + y : $.pageYOffset || 0 + }; + } + else + { + var doc = $.document; + return { + x : doc.documentElement.scrollLeft || doc.body.scrollLeft || 0, + y : doc.documentElement.scrollTop || doc.body.scrollTop || 0 + }; + } + } + }); Index: 3rdParty_sources/ckeditor/core/htmlparser/basicwriter.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/core/htmlparser/basicwriter.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/core/htmlparser/basicwriter.js 17 Aug 2012 14:15:48 -0000 1.1 @@ -0,0 +1,145 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +CKEDITOR.htmlParser.basicWriter = CKEDITOR.tools.createClass( +{ + $ : function() + { + this._ = + { + output : [] + }; + }, + + proto : + { + /** + * Writes the tag opening part for a opener tag. + * @param {String} tagName The element name for this tag. + * @param {Object} attributes The attributes defined for this tag. The + * attributes could be used to inspect the tag. + * @example + * // Writes "<p". + * writer.openTag( 'p', { class : 'MyClass', id : 'MyId' } ); + */ + openTag : function( tagName, attributes ) + { + this._.output.push( '<', tagName ); + }, + + /** + * Writes the tag closing part for a opener tag. + * @param {String} tagName The element name for this tag. + * @param {Boolean} isSelfClose Indicates that this is a self-closing tag, + * like "br" or "img". + * @example + * // Writes ">". + * writer.openTagClose( 'p', false ); + * @example + * // Writes " />". + * writer.openTagClose( 'br', true ); + */ + openTagClose : function( tagName, isSelfClose ) + { + if ( isSelfClose ) + this._.output.push( ' />' ); + else + this._.output.push( '>' ); + }, + + /** + * Writes an attribute. This function should be called after opening the + * tag with {@link #openTagClose}. + * @param {String} attName The attribute name. + * @param {String} attValue The attribute value. + * @example + * // Writes ' class="MyClass"'. + * writer.attribute( 'class', 'MyClass' ); + */ + attribute : function( attName, attValue ) + { + // Browsers don't always escape special character in attribute values. (#4683, #4719). + if ( typeof attValue == 'string' ) + attValue = CKEDITOR.tools.htmlEncodeAttr( attValue ); + + this._.output.push( ' ', attName, '="', attValue, '"' ); + }, + + /** + * Writes a closer tag. + * @param {String} tagName The element name for this tag. + * @example + * // Writes "</p>". + * writer.closeTag( 'p' ); + */ + closeTag : function( tagName ) + { + this._.output.push( '' ); + }, + + /** + * Writes text. + * @param {String} text The text value + * @example + * // Writes "Hello Word". + * writer.text( 'Hello Word' ); + */ + text : function( text ) + { + this._.output.push( text ); + }, + + /** + * Writes a comment. + * @param {String} comment The comment text. + * @example + * // Writes "<!-- My comment -->". + * writer.comment( ' My comment ' ); + */ + comment : function( comment ) + { + this._.output.push( '' ); + }, + + /** + * Writes any kind of data to the ouput. + * @example + * writer.write( 'This is an <b>example</b>.' ); + */ + write : function( data ) + { + this._.output.push( data ); + }, + + /** + * Empties the current output buffer. + * @example + * writer.reset(); + */ + reset : function() + { + this._.output = []; + this._.indent = false; + }, + + /** + * Empties the current output buffer. + * @param {Boolean} reset Indicates that the {@link reset} function is to + * be automatically called after retrieving the HTML. + * @returns {String} The HTML written to the writer so far. + * @example + * var html = writer.getHtml(); + */ + getHtml : function( reset ) + { + var html = this._.output.join( '' ); + + if ( reset ) + this.reset(); + + return html; + } + } +}); Index: 3rdParty_sources/ckeditor/core/htmlparser/cdata.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/core/htmlparser/cdata.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/core/htmlparser/cdata.js 17 Aug 2012 14:15:48 -0000 1.1 @@ -0,0 +1,43 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +(function() +{ + + /** + * A lightweight representation of HTML text. + * @constructor + * @example + */ + CKEDITOR.htmlParser.cdata = function( value ) + { + /** + * The CDATA value. + * @type String + * @example + */ + this.value = value; + }; + + CKEDITOR.htmlParser.cdata.prototype = + { + /** + * CDATA has the same type as {@link CKEDITOR.htmlParser.text} This is + * a constant value set to {@link CKEDITOR.NODE_TEXT}. + * @type Number + * @example + */ + type : CKEDITOR.NODE_TEXT, + + /** + * Writes write the CDATA with no special manipulations. + * @param {CKEDITOR.htmlWriter} writer The writer to which write the HTML. + */ + writeHtml : function( writer ) + { + writer.write( this.value ); + } + }; +})(); Index: 3rdParty_sources/ckeditor/core/htmlparser/comment.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/core/htmlparser/comment.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/core/htmlparser/comment.js 17 Aug 2012 14:15:48 -0000 1.1 @@ -0,0 +1,60 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * A lightweight representation of an HTML comment. + * @constructor + * @example + */ +CKEDITOR.htmlParser.comment = function( value ) +{ + /** + * The comment text. + * @type String + * @example + */ + this.value = value; + + /** @private */ + this._ = + { + isBlockLike : false + }; +}; + +CKEDITOR.htmlParser.comment.prototype = +{ + /** + * The node type. This is a constant value set to {@link CKEDITOR.NODE_COMMENT}. + * @type Number + * @example + */ + type : CKEDITOR.NODE_COMMENT, + + /** + * Writes the HTML representation of this comment to a CKEDITOR.htmlWriter. + * @param {CKEDITOR.htmlWriter} writer The writer to which write the HTML. + * @example + */ + writeHtml : function( writer, filter ) + { + var comment = this.value; + + if ( filter ) + { + if ( !( comment = filter.onComment( comment, this ) ) ) + return; + + if ( typeof comment != 'string' ) + { + comment.parent = this.parent; + comment.writeHtml( writer, filter ); + return; + } + } + + writer.comment( comment ); + } +}; Index: 3rdParty_sources/ckeditor/core/htmlparser/element.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/core/htmlparser/element.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/core/htmlparser/element.js 17 Aug 2012 14:15:48 -0000 1.1 @@ -0,0 +1,308 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * A lightweight representation of an HTML element. + * @param {String} name The element name. + * @param {Object} attributes And object holding all attributes defined for + * this element. + * @constructor + * @example + */ +CKEDITOR.htmlParser.element = function( name, attributes ) +{ + /** + * The element name. + * @type String + * @example + */ + this.name = name; + + /** + * Holds the attributes defined for this element. + * @type Object + * @example + */ + this.attributes = attributes || ( attributes = {} ); + + /** + * The nodes that are direct children of this element. + * @type Array + * @example + */ + this.children = []; + + var tagName = attributes[ 'data-cke-real-element-type' ] || name || ''; + + // Reveal the real semantic of our internal custom tag name (#6639). + var internalTag = tagName.match( /^cke:(.*)/ ); + internalTag && ( tagName = internalTag[ 1 ] ); + + var dtd = CKEDITOR.dtd, + isBlockLike = !!( dtd.$nonBodyContent[ tagName ] + || dtd.$block[ tagName ] + || dtd.$listItem[ tagName ] + || dtd.$tableContent[ tagName ] + || dtd.$nonEditable[ tagName ] + || tagName == 'br' ), + isEmpty = !!dtd.$empty[ name ]; + + this.isEmpty = isEmpty; + this.isUnknown = !dtd[ name ]; + + /** @private */ + this._ = + { + isBlockLike : isBlockLike, + hasInlineStarted : isEmpty || !isBlockLike + }; +}; + +/** + * Object presentation of CSS style declaration text. + * @param {CKEDITOR.htmlParser.element|String} elementOrStyleText A html parser element or the inline style text. + */ +CKEDITOR.htmlParser.cssStyle = function() +{ + var styleText, + arg = arguments[ 0 ], + rules = {}; + + styleText = arg instanceof CKEDITOR.htmlParser.element ? arg.attributes.style : arg; + + // html-encoded quote might be introduced by 'font-family' + // from MS-Word which confused the following regexp. e.g. + //'font-family: "Lucida, Console"' + ( styleText || '' ) + .replace( /"/g, '"' ) + .replace( /\s*([^ :;]+)\s*:\s*([^;]+)\s*(?=;|$)/g, + function( match, name, value ) + { + name == 'font-family' && ( value = value.replace( /["']/g, '' ) ); + rules[ name.toLowerCase() ] = value; + }); + + return { + + rules : rules, + + /** + * Apply the styles onto the specified element or object. + * @param {CKEDITOR.htmlParser.element|CKEDITOR.dom.element|Object} obj + */ + populate : function( obj ) + { + var style = this.toString(); + if ( style ) + { + obj instanceof CKEDITOR.dom.element ? + obj.setAttribute( 'style', style ) : + obj instanceof CKEDITOR.htmlParser.element ? + obj.attributes.style = style : + obj.style = style; + } + }, + + toString : function() + { + var output = []; + for ( var i in rules ) + rules[ i ] && output.push( i, ':', rules[ i ], ';' ); + return output.join( '' ); + } + }; +}; + +(function() +{ + // Used to sort attribute entries in an array, where the first element of + // each object is the attribute name. + var sortAttribs = function( a, b ) + { + a = a[0]; + b = b[0]; + return a < b ? -1 : a > b ? 1 : 0; + }; + + CKEDITOR.htmlParser.element.prototype = + { + /** + * The node type. This is a constant value set to {@link CKEDITOR.NODE_ELEMENT}. + * @type Number + * @example + */ + type : CKEDITOR.NODE_ELEMENT, + + /** + * Adds a node to the element children list. + * @param {Object} node The node to be added. It can be any of of the + * following types: {@link CKEDITOR.htmlParser.element}, + * {@link CKEDITOR.htmlParser.text} and + * {@link CKEDITOR.htmlParser.comment}. + * @function + * @example + */ + add : CKEDITOR.htmlParser.fragment.prototype.add, + + /** + * Clone this element. + * @returns {CKEDITOR.htmlParser.element} The element clone. + * @example + */ + clone : function() + { + return new CKEDITOR.htmlParser.element( this.name, this.attributes ); + }, + + /** + * Writes the element HTML to a CKEDITOR.htmlWriter. + * @param {CKEDITOR.htmlWriter} writer The writer to which write the HTML. + * @example + */ + writeHtml : function( writer, filter ) + { + var attributes = this.attributes; + + // Ignore cke: prefixes when writing HTML. + var element = this, + writeName = element.name, + a, newAttrName, value; + + var isChildrenFiltered; + + /** + * Providing an option for bottom-up filtering order ( element + * children to be pre-filtered before the element itself ). + */ + element.filterChildren = function() + { + if ( !isChildrenFiltered ) + { + var writer = new CKEDITOR.htmlParser.basicWriter(); + CKEDITOR.htmlParser.fragment.prototype.writeChildrenHtml.call( element, writer, filter ); + element.children = new CKEDITOR.htmlParser.fragment.fromHtml( writer.getHtml(), 0, element.clone() ).children; + isChildrenFiltered = 1; + } + }; + + if ( filter ) + { + while ( true ) + { + if ( !( writeName = filter.onElementName( writeName ) ) ) + return; + + element.name = writeName; + + if ( !( element = filter.onElement( element ) ) ) + return; + + element.parent = this.parent; + + if ( element.name == writeName ) + break; + + // If the element has been replaced with something of a + // different type, then make the replacement write itself. + if ( element.type != CKEDITOR.NODE_ELEMENT ) + { + element.writeHtml( writer, filter ); + return; + } + + writeName = element.name; + + // This indicate that the element has been dropped by + // filter but not the children. + if ( !writeName ) + { + // Fix broken parent refs. + for ( var c = 0, length = this.children.length ; c < length ; c++ ) + this.children[ c ].parent = element.parent; + + this.writeChildrenHtml.call( element, writer, isChildrenFiltered ? null : filter ); + return; + } + } + + // The element may have been changed, so update the local + // references. + attributes = element.attributes; + } + + // Open element tag. + writer.openTag( writeName, attributes ); + + // Copy all attributes to an array. + var attribsArray = []; + // Iterate over the attributes twice since filters may alter + // other attributes. + for ( var i = 0 ; i < 2; i++ ) + { + for ( a in attributes ) + { + newAttrName = a; + value = attributes[ a ]; + if ( i == 1 ) + attribsArray.push( [ a, value ] ); + else if ( filter ) + { + while ( true ) + { + if ( !( newAttrName = filter.onAttributeName( a ) ) ) + { + delete attributes[ a ]; + break; + } + else if ( newAttrName != a ) + { + delete attributes[ a ]; + a = newAttrName; + continue; + } + else + break; + } + if ( newAttrName ) + { + if ( ( value = filter.onAttribute( element, newAttrName, value ) ) === false ) + delete attributes[ newAttrName ]; + else + attributes [ newAttrName ] = value; + } + } + } + } + // Sort the attributes by name. + if ( writer.sortAttributes ) + attribsArray.sort( sortAttribs ); + + // Send the attributes. + var len = attribsArray.length; + for ( i = 0 ; i < len ; i++ ) + { + var attrib = attribsArray[ i ]; + writer.attribute( attrib[0], attrib[1] ); + } + + // Close the tag. + writer.openTagClose( writeName, element.isEmpty ); + + if ( !element.isEmpty ) + { + this.writeChildrenHtml.call( element, writer, isChildrenFiltered ? null : filter ); + // Close the element. + writer.closeTag( writeName ); + } + }, + + writeChildrenHtml : function( writer, filter ) + { + // Send children. + CKEDITOR.htmlParser.fragment.prototype.writeChildrenHtml.apply( this, arguments ); + + } + }; +})(); Index: 3rdParty_sources/ckeditor/core/htmlparser/filter.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/core/htmlparser/filter.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/core/htmlparser/filter.js 17 Aug 2012 14:15:48 -0000 1.1 @@ -0,0 +1,288 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +(function() +{ + CKEDITOR.htmlParser.filter = CKEDITOR.tools.createClass( + { + $ : function( rules ) + { + this._ = + { + elementNames : [], + attributeNames : [], + elements : { $length : 0 }, + attributes : { $length : 0 } + }; + + if ( rules ) + this.addRules( rules, 10 ); + }, + + proto : + { + addRules : function( rules, priority ) + { + if ( typeof priority != 'number' ) + priority = 10; + + // Add the elementNames. + addItemsToList( this._.elementNames, rules.elementNames, priority ); + + // Add the attributeNames. + addItemsToList( this._.attributeNames, rules.attributeNames, priority ); + + // Add the elements. + addNamedItems( this._.elements, rules.elements, priority ); + + // Add the attributes. + addNamedItems( this._.attributes, rules.attributes, priority ); + + // Add the text. + this._.text = transformNamedItem( this._.text, rules.text, priority ) || this._.text; + + // Add the comment. + this._.comment = transformNamedItem( this._.comment, rules.comment, priority ) || this._.comment; + + // Add root fragment. + this._.root = transformNamedItem( this._.root, rules.root, priority ) || this._.root; + }, + + onElementName : function( name ) + { + return filterName( name, this._.elementNames ); + }, + + onAttributeName : function( name ) + { + return filterName( name, this._.attributeNames ); + }, + + onText : function( text ) + { + var textFilter = this._.text; + return textFilter ? textFilter.filter( text ) : text; + }, + + onComment : function( commentText, comment ) + { + var textFilter = this._.comment; + return textFilter ? textFilter.filter( commentText, comment ) : commentText; + }, + + onFragment : function( element ) + { + var rootFilter = this._.root; + return rootFilter ? rootFilter.filter( element ) : element; + }, + + onElement : function( element ) + { + // We must apply filters set to the specific element name as + // well as those set to the generic $ name. So, add both to an + // array and process them in a small loop. + var filters = [ this._.elements[ '^' ], this._.elements[ element.name ], this._.elements.$ ], + filter, ret; + + for ( var i = 0 ; i < 3 ; i++ ) + { + filter = filters[ i ]; + if ( filter ) + { + ret = filter.filter( element, this ); + + if ( ret === false ) + return null; + + if ( ret && ret != element ) + return this.onNode( ret ); + + // The non-root element has been dismissed by one of the filters. + if ( element.parent && !element.name ) + break; + } + } + + return element; + }, + + onNode : function( node ) + { + var type = node.type; + + return type == CKEDITOR.NODE_ELEMENT ? this.onElement( node ) : + type == CKEDITOR.NODE_TEXT ? new CKEDITOR.htmlParser.text( this.onText( node.value ) ) : + type == CKEDITOR.NODE_COMMENT ? new CKEDITOR.htmlParser.comment( this.onComment( node.value ) ): + null; + }, + + onAttribute : function( element, name, value ) + { + var filter = this._.attributes[ name ]; + + if ( filter ) + { + var ret = filter.filter( value, element, this ); + + if ( ret === false ) + return false; + + if ( typeof ret != 'undefined' ) + return ret; + } + + return value; + } + } + }); + + function filterName( name, filters ) + { + for ( var i = 0 ; name && i < filters.length ; i++ ) + { + var filter = filters[ i ]; + name = name.replace( filter[ 0 ], filter[ 1 ] ); + } + return name; + } + + function addItemsToList( list, items, priority ) + { + if ( typeof items == 'function' ) + items = [ items ]; + + var i, j, + listLength = list.length, + itemsLength = items && items.length; + + if ( itemsLength ) + { + // Find the index to insert the items at. + for ( i = 0 ; i < listLength && list[ i ].pri < priority ; i++ ) + { /*jsl:pass*/ } + + // Add all new items to the list at the specific index. + for ( j = itemsLength - 1 ; j >= 0 ; j-- ) + { + var item = items[ j ]; + if ( item ) + { + item.pri = priority; + list.splice( i, 0, item ); + } + } + } + } + + function addNamedItems( hashTable, items, priority ) + { + if ( items ) + { + for ( var name in items ) + { + var current = hashTable[ name ]; + + hashTable[ name ] = + transformNamedItem( + current, + items[ name ], + priority ); + + if ( !current ) + hashTable.$length++; + } + } + } + + function transformNamedItem( current, item, priority ) + { + if ( item ) + { + item.pri = priority; + + if ( current ) + { + // If the current item is not an Array, transform it. + if ( !current.splice ) + { + if ( current.pri > priority ) + current = [ item, current ]; + else + current = [ current, item ]; + + current.filter = callItems; + } + else + addItemsToList( current, item, priority ); + + return current; + } + else + { + item.filter = item; + return item; + } + } + } + + // Invoke filters sequentially on the array, break the iteration + // when it doesn't make sense to continue anymore. + function callItems( currentEntry ) + { + var isNode = currentEntry.type + || currentEntry instanceof CKEDITOR.htmlParser.fragment; + + for ( var i = 0 ; i < this.length ; i++ ) + { + // Backup the node info before filtering. + if ( isNode ) + { + var orgType = currentEntry.type, + orgName = currentEntry.name; + } + + var item = this[ i ], + ret = item.apply( window, arguments ); + + if ( ret === false ) + return ret; + + // We're filtering node (element/fragment). + if ( isNode ) + { + // No further filtering if it's not anymore + // fitable for the subsequent filters. + if ( ret && ( ret.name != orgName + || ret.type != orgType ) ) + { + return ret; + } + } + // Filtering value (nodeName/textValue/attrValue). + else + { + // No further filtering if it's not + // any more values. + if ( typeof ret != 'string' ) + return ret; + } + + ret != undefined && ( currentEntry = ret ); + } + + return currentEntry; + } +})(); + +// "entities" plugin +/* +{ + text : function( text ) + { + // TODO : Process entities. + return text.toUpperCase(); + } +}; +*/ Index: 3rdParty_sources/ckeditor/core/htmlparser/fragment.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/core/htmlparser/fragment.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/core/htmlparser/fragment.js 17 Aug 2012 14:15:48 -0000 1.1 @@ -0,0 +1,518 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * A lightweight representation of an HTML DOM structure. + * @constructor + * @example + */ +CKEDITOR.htmlParser.fragment = function() +{ + /** + * The nodes contained in the root of this fragment. + * @type Array + * @example + * var fragment = CKEDITOR.htmlParser.fragment.fromHtml( 'Sample Text' ); + * alert( fragment.children.length ); "2" + */ + this.children = []; + + /** + * Get the fragment parent. Should always be null. + * @type Object + * @default null + * @example + */ + this.parent = null; + + /** @private */ + this._ = + { + isBlockLike : true, + hasInlineStarted : false + }; +}; + +(function() +{ + // Block-level elements whose internal structure should be respected during + // parser fixing. + var nonBreakingBlocks = CKEDITOR.tools.extend( { table:1,ul:1,ol:1,dl:1 }, CKEDITOR.dtd.table, CKEDITOR.dtd.ul, CKEDITOR.dtd.ol, CKEDITOR.dtd.dl ); + + // IE < 8 don't output the close tag on definition list items. (#6975) + var optionalCloseTags = CKEDITOR.env.ie && CKEDITOR.env.version < 8 ? { dd : 1, dt :1 } : {}; + + var listBlocks = { ol:1, ul:1 }; + + // Dtd of the fragment element, basically it accept anything except for intermediate structure, e.g. orphan
    1. . + var rootDtd = CKEDITOR.tools.extend( {}, { html: 1 }, CKEDITOR.dtd.html, CKEDITOR.dtd.body, CKEDITOR.dtd.head, { style:1,script:1 } ); + + function isRemoveEmpty( node ) + { + // Empty link is to be removed when empty but not anchor. (#7894) + return node.name == 'a' && node.attributes.href + || CKEDITOR.dtd.$removeEmpty[ node.name ]; + } + + /** + * Creates a {@link CKEDITOR.htmlParser.fragment} from an HTML string. + * @param {String} fragmentHtml The HTML to be parsed, filling the fragment. + * @param {Number} [fixForBody=false] Wrap body with specified element if needed. + * @param {CKEDITOR.htmlParser.element} contextNode Parse the html as the content of this element. + * @returns CKEDITOR.htmlParser.fragment The fragment created. + * @example + * var fragment = CKEDITOR.htmlParser.fragment.fromHtml( 'Sample Text' ); + * alert( fragment.children[0].name ); "b" + * alert( fragment.children[1].value ); " Text" + */ + CKEDITOR.htmlParser.fragment.fromHtml = function( fragmentHtml, fixForBody, contextNode ) + { + var parser = new CKEDITOR.htmlParser(), + fragment = contextNode || new CKEDITOR.htmlParser.fragment(), + pendingInline = [], + pendingBRs = [], + currentNode = fragment, + // Indicate we're inside a ' ); + return html.join( '' ); + }; + CKEDITOR.ui.dialog.labeledElement.call( this, dialog, elementDefinition, htmlList, innerHTML ); + }, + + /** + * A single checkbox with a label on the right. + * @constructor + * @extends CKEDITOR.ui.dialog.uiElement + * @example + * @param {CKEDITOR.dialog} dialog + * Parent dialog object. + * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition + * The element definition. Accepted fields: + *
        + *
      • checked (Optional) Whether the checkbox is checked + * on instantiation. Defaults to false.
      • + *
      • validate (Optional) The validation function.
      • + *
      • label (Optional) The checkbox label.
      • + *
      + * @param {Array} htmlList + * List of HTML code to output to. + */ + checkbox : function( dialog, elementDefinition, htmlList ) + { + if ( arguments.length < 3 ) + return; + + var _ = initPrivateObject.call( this, elementDefinition, { 'default' : !!elementDefinition[ 'default' ] } ); + + if ( elementDefinition.validate ) + this.validate = elementDefinition.validate; + + /** @ignore */ + var innerHTML = function() + { + var myDefinition = CKEDITOR.tools.extend( {}, elementDefinition, + { + id : elementDefinition.id ? elementDefinition.id + '_checkbox' : CKEDITOR.tools.getNextId() + '_checkbox' + }, true ), + html = []; + + var labelId = CKEDITOR.tools.getNextId() + '_label'; + var attributes = { 'class' : 'cke_dialog_ui_checkbox_input', type : 'checkbox', 'aria-labelledby' : labelId }; + cleanInnerDefinition( myDefinition ); + if ( elementDefinition[ 'default' ] ) + attributes.checked = 'checked'; + + if ( typeof myDefinition.inputStyle != 'undefined' ) + myDefinition.style = myDefinition.inputStyle; + + _.checkbox = new CKEDITOR.ui.dialog.uiElement( dialog, myDefinition, html, 'input', null, attributes ); + html.push( ' ' ); + return html.join( '' ); + }; + + CKEDITOR.ui.dialog.uiElement.call( this, dialog, elementDefinition, htmlList, 'span', null, null, innerHTML ); + }, + + /** + * A group of radio buttons. + * @constructor + * @example + * @extends CKEDITOR.ui.dialog.labeledElement + * @param {CKEDITOR.dialog} dialog + * Parent dialog object. + * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition + * The element definition. Accepted fields: + *
        + *
      • default (Required) The default value.
      • + *
      • validate (Optional) The validation function.
      • + *
      • items (Required) An array of options. Each option + * is a 1- or 2-item array of format [ 'Description', 'Value' ]. If 'Value' + * is missing, then the value would be assumed to be the same as the + * description.
      • + *
      + * @param {Array} htmlList + * List of HTML code to output to. + */ + radio : function( dialog, elementDefinition, htmlList ) + { + if ( arguments.length < 3) + return; + + initPrivateObject.call( this, elementDefinition ); + if ( !this._['default'] ) + this._['default'] = this._.initValue = elementDefinition.items[0][1]; + if ( elementDefinition.validate ) + this.validate = elementDefinition.valdiate; + var children = [], me = this; + + /** @ignore */ + var innerHTML = function() + { + var inputHtmlList = [], html = [], + commonAttributes = { 'class' : 'cke_dialog_ui_radio_item', 'aria-labelledby' : this._.labelId }, + commonName = elementDefinition.id ? elementDefinition.id + '_radio' : CKEDITOR.tools.getNextId() + '_radio'; + for ( var i = 0 ; i < elementDefinition.items.length ; i++ ) + { + var item = elementDefinition.items[i], + title = item[2] !== undefined ? item[2] : item[0], + value = item[1] !== undefined ? item[1] : item[0], + inputId = CKEDITOR.tools.getNextId() + '_radio_input', + labelId = inputId + '_label', + inputDefinition = CKEDITOR.tools.extend( {}, elementDefinition, + { + id : inputId, + title : null, + type : null + }, true ), + labelDefinition = CKEDITOR.tools.extend( {}, inputDefinition, + { + title : title + }, true ), + inputAttributes = + { + type : 'radio', + 'class' : 'cke_dialog_ui_radio_input', + name : commonName, + value : value, + 'aria-labelledby' : labelId + }, + inputHtml = []; + if ( me._['default'] == value ) + inputAttributes.checked = 'checked'; + cleanInnerDefinition( inputDefinition ); + cleanInnerDefinition( labelDefinition ); + + if ( typeof inputDefinition.inputStyle != 'undefined' ) + inputDefinition.style = inputDefinition.inputStyle; + + children.push( new CKEDITOR.ui.dialog.uiElement( dialog, inputDefinition, inputHtml, 'input', null, inputAttributes ) ); + inputHtml.push( ' ' ); + new CKEDITOR.ui.dialog.uiElement( dialog, labelDefinition, inputHtml, 'label', null, { id : labelId, 'for' : inputAttributes.id }, + item[0] ); + inputHtmlList.push( inputHtml.join( '' ) ); + } + new CKEDITOR.ui.dialog.hbox( dialog, children, inputHtmlList, html ); + return html.join( '' ); + }; + + CKEDITOR.ui.dialog.labeledElement.call( this, dialog, elementDefinition, htmlList, innerHTML ); + this._.children = children; + }, + + /** + * A button with a label inside. + * @constructor + * @example + * @extends CKEDITOR.ui.dialog.uiElement + * @param {CKEDITOR.dialog} dialog + * Parent dialog object. + * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition + * The element definition. Accepted fields: + *
        + *
      • label (Required) The button label.
      • + *
      • disabled (Optional) Set to true if you want the + * button to appear in disabled state.
      • + *
      + * @param {Array} htmlList + * List of HTML code to output to. + */ + button : function( dialog, elementDefinition, htmlList ) + { + if ( !arguments.length ) + return; + + if ( typeof elementDefinition == 'function' ) + elementDefinition = elementDefinition( dialog.getParentEditor() ); + + initPrivateObject.call( this, elementDefinition, { disabled : elementDefinition.disabled || false } ); + + // Add OnClick event to this input. + CKEDITOR.event.implementOn( this ); + + var me = this; + + // Register an event handler for processing button clicks. + dialog.on( 'load', function( eventInfo ) + { + var element = this.getElement(); + + (function() + { + element.on( 'click', function( evt ) + { + me.fire( 'click', { dialog : me.getDialog() } ); + evt.data.preventDefault(); + } ); + + element.on( 'keydown', function( evt ) + { + if ( evt.data.getKeystroke() in { 32:1 } ) + { + me.click(); + evt.data.preventDefault(); + } + } ); + })(); + + element.unselectable(); + }, this ); + + var outerDefinition = CKEDITOR.tools.extend( {}, elementDefinition ); + delete outerDefinition.style; + + var labelId = CKEDITOR.tools.getNextId() + '_label'; + CKEDITOR.ui.dialog.uiElement.call( + this, + dialog, + outerDefinition, + htmlList, + 'a', + null, + { + style : elementDefinition.style, + href : 'javascript:void(0)', + title : elementDefinition.label, + hidefocus : 'true', + 'class' : elementDefinition['class'], + role : 'button', + 'aria-labelledby' : labelId + }, + '' + + CKEDITOR.tools.htmlEncode( elementDefinition.label ) + + '' ); + }, + + /** + * A select box. + * @extends CKEDITOR.ui.dialog.uiElement + * @example + * @constructor + * @param {CKEDITOR.dialog} dialog + * Parent dialog object. + * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition + * The element definition. Accepted fields: + *
        + *
      • default (Required) The default value.
      • + *
      • validate (Optional) The validation function.
      • + *
      • items (Required) An array of options. Each option + * is a 1- or 2-item array of format [ 'Description', 'Value' ]. If 'Value' + * is missing, then the value would be assumed to be the same as the + * description.
      • + *
      • multiple (Optional) Set this to true if you'd like + * to have a multiple-choice select box.
      • + *
      • size (Optional) The number of items to display in + * the select box.
      • + *
      + * @param {Array} htmlList + * List of HTML code to output to. + */ + select : function( dialog, elementDefinition, htmlList ) + { + if ( arguments.length < 3 ) + return; + + var _ = initPrivateObject.call( this, elementDefinition ); + + if ( elementDefinition.validate ) + this.validate = elementDefinition.validate; + + _.inputId = CKEDITOR.tools.getNextId() + '_select'; + /** @ignore */ + var innerHTML = function() + { + var myDefinition = CKEDITOR.tools.extend( {}, elementDefinition, + { + id : elementDefinition.id ? elementDefinition.id + '_select' : CKEDITOR.tools.getNextId() + '_select' + }, true ), + html = [], + innerHTML = [], + attributes = { 'id' : _.inputId, 'class' : 'cke_dialog_ui_input_select', 'aria-labelledby' : this._.labelId }; + + // Add multiple and size attributes from element definition. + if ( elementDefinition.size != undefined ) + attributes.size = elementDefinition.size; + if ( elementDefinition.multiple != undefined ) + attributes.multiple = elementDefinition.multiple; + + cleanInnerDefinition( myDefinition ); + for ( var i = 0, item ; i < elementDefinition.items.length && ( item = elementDefinition.items[i] ) ; i++ ) + { + innerHTML.push( '
    2. child (nested + // lists) or the next sibling
    3. . + + this._.nextNode = ( block.equals( lastNode ) ? null : getNextSourceNode( range.getBoundaryNodes().endNode, 1, lastNode ) ); + } + } + + if ( removePreviousBr ) + { + var previousSibling = block.getPrevious(); + if ( previousSibling && previousSibling.type == CKEDITOR.NODE_ELEMENT ) + { + if ( previousSibling.getName() == 'br' ) + previousSibling.remove(); + else if ( previousSibling.getLast() && previousSibling.getLast().$.nodeName.toLowerCase() == 'br' ) + previousSibling.getLast().remove(); + } + } + + if ( removeLastBr ) + { + var lastChild = block.getLast(); + if ( lastChild && lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.getName() == 'br' ) + { + // Take care not to remove the block expanding
      in non-IE browsers. + if ( CKEDITOR.env.ie + || lastChild.getPrevious( bookmarkGuard ) + || lastChild.getNext( bookmarkGuard ) ) + lastChild.remove(); + } + } + + // Get a reference for the next element. This is important because the + // above block can be removed or changed, so we can rely on it for the + // next interation. + if ( !this._.nextNode ) + { + this._.nextNode = ( isLast || block.equals( lastNode ) ) ? null : + getNextSourceNode( block, 1, lastNode ); + } + + return block; + } + }; + + CKEDITOR.dom.range.prototype.createIterator = function() + { + return new iterator( this ); + }; +})(); Index: 3rdParty_sources/ckeditor/plugins/editingblock/plugin.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/plugins/editingblock/plugin.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/plugins/editingblock/plugin.js 17 Aug 2012 14:15:50 -0000 1.1 @@ -0,0 +1,278 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * @fileOverview The default editing block plugin, which holds the editing area + * and source view. + */ + +(function() +{ + // This is a semaphore used to avoid recursive calls between + // the following data handling functions. + var isHandlingData; + + CKEDITOR.plugins.add( 'editingblock', + { + init : function( editor ) + { + if ( !editor.config.editingBlock ) + return; + + editor.on( 'themeSpace', function( event ) + { + if ( event.data.space == 'contents' ) + event.data.html += '
      '; + }); + + editor.on( 'themeLoaded', function() + { + editor.fireOnce( 'editingBlockReady' ); + }); + + editor.on( 'uiReady', function() + { + editor.setMode( editor.config.startupMode ); + }); + + editor.on( 'afterSetData', function() + { + if ( !isHandlingData ) + { + function setData() + { + isHandlingData = true; + editor.getMode().loadData( editor.getData() ); + isHandlingData = false; + } + + if ( editor.mode ) + setData(); + else + { + editor.on( 'mode', function() + { + if ( editor.mode ) + { + setData(); + editor.removeListener( 'mode', arguments.callee ); + } + }); + } + } + }); + + editor.on( 'beforeGetData', function() + { + if ( !isHandlingData && editor.mode ) + { + isHandlingData = true; + editor.setData( editor.getMode().getData(), null, 1 ); + isHandlingData = false; + } + }); + + editor.on( 'getSnapshot', function( event ) + { + if ( editor.mode ) + event.data = editor.getMode().getSnapshotData(); + }); + + editor.on( 'loadSnapshot', function( event ) + { + if ( editor.mode ) + editor.getMode().loadSnapshotData( event.data ); + }); + + // For the first "mode" call, we'll also fire the "instanceReady" + // event. + editor.on( 'mode', function( event ) + { + // Do that once only. + event.removeListener(); + + // Redirect the focus into editor for webkit. (#5713) + CKEDITOR.env.webkit && editor.container.on( 'focus', function() + { + editor.focus(); + }); + + if ( editor.config.startupFocus ) + editor.focus(); + + // Fire instanceReady for both the editor and CKEDITOR, but + // defer this until the whole execution has completed + // to guarantee the editor is fully responsible. + setTimeout( function(){ + editor.fireOnce( 'instanceReady' ); + CKEDITOR.fire( 'instanceReady', null, editor ); + }, 0 ); + }); + + editor.on( 'destroy', function () + { + // -> currentMode.unload( holderElement ); + if ( this.mode ) + this._.modes[ this.mode ].unload( this.getThemeSpace( 'contents' ) ); + }); + } + }); + + /** + * The current editing mode. An editing mode is basically a viewport for + * editing or content viewing. By default the possible values for this + * property are "wysiwyg" and "source". + * @type String + * @example + * alert( CKEDITOR.instances.editor1.mode ); // "wysiwyg" (e.g.) + */ + CKEDITOR.editor.prototype.mode = ''; + + /** + * Registers an editing mode. This function is to be used mainly by plugins. + * @param {String} mode The mode name. + * @param {Object} modeEditor The mode editor definition. + * @example + */ + CKEDITOR.editor.prototype.addMode = function( mode, modeEditor ) + { + modeEditor.name = mode; + ( this._.modes || ( this._.modes = {} ) )[ mode ] = modeEditor; + }; + + /** + * Sets the current editing mode in this editor instance. + * @param {String} mode A registered mode name. + * @example + * // Switch to "source" view. + * CKEDITOR.instances.editor1.setMode( 'source' ); + */ + CKEDITOR.editor.prototype.setMode = function( mode ) + { + this.fire( 'beforeSetMode', { newMode : mode } ); + + var data, + holderElement = this.getThemeSpace( 'contents' ), + isDirty = this.checkDirty(); + + // Unload the previous mode. + if ( this.mode ) + { + if ( mode == this.mode ) + return; + + this._.previousMode = this.mode; + + this.fire( 'beforeModeUnload' ); + + var currentMode = this.getMode(); + data = currentMode.getData(); + currentMode.unload( holderElement ); + this.mode = ''; + } + + holderElement.setHtml( '' ); + + // Load required mode. + var modeEditor = this.getMode( mode ); + if ( !modeEditor ) + throw '[CKEDITOR.editor.setMode] Unknown mode "' + mode + '".'; + + if ( !isDirty ) + { + this.on( 'mode', function() + { + this.resetDirty(); + this.removeListener( 'mode', arguments.callee ); + }); + } + + modeEditor.load( holderElement, ( typeof data ) != 'string' ? this.getData() : data ); + }; + + /** + * Gets the current or any of the objects that represent the editing + * area modes. The two most common editing modes are "wysiwyg" and "source". + * @param {String} [mode] The mode to be retrieved. If not specified, the + * current one is returned. + */ + CKEDITOR.editor.prototype.getMode = function( mode ) + { + return this._.modes && this._.modes[ mode || this.mode ]; + }; + + /** + * Moves the selection focus to the editing are space in the editor. + */ + CKEDITOR.editor.prototype.focus = function() + { + this.forceNextSelectionCheck(); + var mode = this.getMode(); + if ( mode ) + mode.focus(); + }; +})(); + +/** + * The mode to load at the editor startup. It depends on the plugins + * loaded. By default, the "wysiwyg" and "source" modes are available. + * @type String + * @default 'wysiwyg' + * @example + * config.startupMode = 'source'; + */ +CKEDITOR.config.startupMode = 'wysiwyg'; + +/** + * Sets whether the editor should have the focus when the page loads. + * @name CKEDITOR.config.startupFocus + * @type Boolean + * @default false + * @example + * config.startupFocus = true; + */ + +/** + * Whether to render or not the editing block area in the editor interface. + * @type Boolean + * @default true + * @example + * config.editingBlock = false; + */ +CKEDITOR.config.editingBlock = true; + +/** + * Fired when a CKEDITOR instance is created, fully initialized and ready for interaction. + * @name CKEDITOR#instanceReady + * @event + * @param {CKEDITOR.editor} editor The editor instance that has been created. + */ + +/** + * Fired when the CKEDITOR instance is created, fully initialized and ready for interaction. + * @name CKEDITOR.editor#instanceReady + * @event + */ + +/** + * Fired before changing the editing mode. See also CKEDITOR.editor#beforeSetMode and CKEDITOR.editor#mode + * @name CKEDITOR.editor#beforeModeUnload + * @event + */ + + /** + * Fired before the editor mode is set. See also CKEDITOR.editor#mode and CKEDITOR.editor#beforeModeUnload + * @name CKEDITOR.editor#beforeSetMode + * @event + * @since 3.5.3 + * @param {String} newMode The name of the mode which is about to be set. + */ + +/** + * Fired after setting the editing mode. See also CKEDITOR.editor#beforeSetMode and CKEDITOR.editor#beforeModeUnload + * @name CKEDITOR.editor#mode + * @event + * @param {String} previousMode The previous mode of the editor. + */ Index: 3rdParty_sources/ckeditor/plugins/elementspath/plugin.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/plugins/elementspath/plugin.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/plugins/elementspath/plugin.js 17 Aug 2012 14:15:51 -0000 1.1 @@ -0,0 +1,218 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * @fileOverview The "elementspath" plugin. It shows all elements in the DOM + * parent tree relative to the current selection in the editing area. + */ + +(function() +{ + var commands = + { + toolbarFocus : + { + editorFocus : false, + readOnly : 1, + exec : function( editor ) + { + var idBase = editor._.elementsPath.idBase; + var element = CKEDITOR.document.getById( idBase + '0' ); + + // Make the first button focus accessible for IE. (#3417) + // Adobe AIR instead need while of delay. + element && element.focus( CKEDITOR.env.ie || CKEDITOR.env.air ); + } + } + }; + + var emptyHtml = ' '; + + CKEDITOR.plugins.add( 'elementspath', + { + requires : [ 'selection' ], + + init : function( editor ) + { + var spaceId = 'cke_path_' + editor.name; + var spaceElement; + var getSpaceElement = function() + { + if ( !spaceElement ) + spaceElement = CKEDITOR.document.getById( spaceId ); + return spaceElement; + }; + + var idBase = 'cke_elementspath_' + CKEDITOR.tools.getNextNumber() + '_'; + + editor._.elementsPath = { idBase : idBase, filters : [] }; + + editor.on( 'themeSpace', function( event ) + { + if ( event.data.space == 'bottom' ) + { + event.data.html += + '' + editor.lang.elementsPath.eleLabel + '' + + '
      ' + emptyHtml + '
      '; + } + }); + + function onClick( elementIndex ) + { + editor.focus(); + var element = editor._.elementsPath.list[ elementIndex ]; + if ( element.is( 'body' ) ) + { + var range = new CKEDITOR.dom.range( editor.document ); + range.selectNodeContents( element ); + range.select(); + } + else + editor.getSelection().selectElement( element ); + } + + var onClickHanlder = CKEDITOR.tools.addFunction( onClick ); + + var onKeyDownHandler = CKEDITOR.tools.addFunction( function( elementIndex, ev ) + { + var idBase = editor._.elementsPath.idBase, + element; + + ev = new CKEDITOR.dom.event( ev ); + + var rtl = editor.lang.dir == 'rtl'; + switch ( ev.getKeystroke() ) + { + case rtl ? 39 : 37 : // LEFT-ARROW + case 9 : // TAB + element = CKEDITOR.document.getById( idBase + ( elementIndex + 1 ) ); + if ( !element ) + element = CKEDITOR.document.getById( idBase + '0' ); + element.focus(); + return false; + + case rtl ? 37 : 39 : // RIGHT-ARROW + case CKEDITOR.SHIFT + 9 : // SHIFT + TAB + element = CKEDITOR.document.getById( idBase + ( elementIndex - 1 ) ); + if ( !element ) + element = CKEDITOR.document.getById( idBase + ( editor._.elementsPath.list.length - 1 ) ); + element.focus(); + return false; + + case 27 : // ESC + editor.focus(); + return false; + + case 13 : // ENTER // Opera + case 32 : // SPACE + onClick( elementIndex ); + return false; + } + return true; + }); + + editor.on( 'selectionChange', function( ev ) + { + var env = CKEDITOR.env, + selection = ev.data.selection, + element = selection.getStartElement(), + html = [], + editor = ev.editor, + elementsList = editor._.elementsPath.list = [], + filters = editor._.elementsPath.filters; + + while ( element ) + { + var ignore = 0, + name; + + if ( element.data( 'cke-display-name' ) ) + name = element.data( 'cke-display-name' ); + else if ( element.data( 'cke-real-element-type' ) ) + name = element.data( 'cke-real-element-type' ); + else + name = element.getName(); + + for ( var i = 0; i < filters.length; i++ ) + { + var ret = filters[ i ]( element, name ); + if ( ret === false ) + { + ignore = 1; + break; + } + name = ret || name; + } + + if ( !ignore ) + { + var index = elementsList.push( element ) - 1; + + // Use this variable to add conditional stuff to the + // HTML (because we are doing it in reverse order... unshift). + var extra = ''; + + // Some browsers don't cancel key events in the keydown but in the + // keypress. + // TODO: Check if really needed for Gecko+Mac. + if ( env.opera || ( env.gecko && env.mac ) ) + extra += ' onkeypress="return false;"'; + + // With Firefox, we need to force the button to redraw, otherwise it + // will remain in the focus state. + if ( env.gecko ) + extra += ' onblur="this.style.cssText = this.style.cssText;"'; + + var label = editor.lang.elementsPath.eleTitle.replace( /%1/, name ); + html.unshift( + '', + name, + '' + label + '', + '' ); + + } + + if ( name == 'body' ) + break; + + element = element.getParent(); + } + + var space = getSpaceElement(); + space.setHtml( html.join('') + emptyHtml ); + editor.fire( 'elementsPathUpdate', { space : space } ); + }); + + function empty() + { + spaceElement && spaceElement.setHtml( emptyHtml ); + delete editor._.elementsPath.list; + } + + editor.on( 'readOnly', empty ); + editor.on( 'contentDomUnload', empty ); + + editor.addCommand( 'elementsPathFocus', commands.toolbarFocus ); + } + }); +})(); + +/** + * Fired when the contents of the elementsPath are changed + * @name CKEDITOR.editor#elementsPathUpdate + * @event + * @param {Object} eventData.space The elementsPath container + */ Index: 3rdParty_sources/ckeditor/plugins/enterkey/plugin.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/plugins/enterkey/plugin.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/plugins/enterkey/plugin.js 17 Aug 2012 14:15:51 -0000 1.1 @@ -0,0 +1,433 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +(function() +{ + CKEDITOR.plugins.add( 'enterkey', + { + requires : [ 'keystrokes', 'indent' ], + + init : function( editor ) + { + editor.addCommand( 'enter', { + modes : { wysiwyg:1 }, + editorFocus : false, + exec : function( editor ){ enter( editor ); } + }); + + editor.addCommand( 'shiftEnter', { + modes : { wysiwyg:1 }, + editorFocus : false, + exec : function( editor ){ shiftEnter( editor ); } + }); + + var keystrokes = editor.keystrokeHandler.keystrokes; + keystrokes[ 13 ] = 'enter'; + keystrokes[ CKEDITOR.SHIFT + 13 ] = 'shiftEnter'; + } + }); + + CKEDITOR.plugins.enterkey = + { + enterBlock : function( editor, mode, range, forceMode ) + { + // Get the range for the current selection. + range = range || getRange( editor ); + + // We may not have valid ranges to work on, like when inside a + // contenteditable=false element. + if ( !range ) + return; + + var doc = range.document; + + var atBlockStart = range.checkStartOfBlock(), + atBlockEnd = range.checkEndOfBlock(), + path = new CKEDITOR.dom.elementPath( range.startContainer ), + block = path.block; + + if ( atBlockStart && atBlockEnd ) + { + // Exit the list when we're inside an empty list item block. (#5376) + if ( block && ( block.is( 'li' ) || block.getParent().is( 'li' ) ) ) + { + editor.execCommand( 'outdent' ); + return; + } + + if ( block && block.getParent().is( 'blockquote' ) ) + { + block.breakParent( block.getParent() ); + + // If we were at the start of
      , there will be an empty element before it now. + if ( !block.getPrevious().getFirst( CKEDITOR.dom.walker.invisible(1) ) ) + block.getPrevious().remove(); + + // If we were at the end of
      , there will be an empty element after it now. + if ( !block.getNext().getFirst( CKEDITOR.dom.walker.invisible(1) ) ) + block.getNext().remove(); + + range.moveToElementEditStart( block ); + range.select(); + return; + } + } + // Don't split
       if we're in the middle of it, act as shift enter key.
      +			else if ( block && block.is( 'pre' ) )
      +			{
      +				if ( !atBlockEnd )
      +				{
      +					enterBr( editor, mode, range, forceMode );
      +					return;
      +				}
      +			}
      +			// Don't split caption blocks. (#7944)
      +			else if ( block && CKEDITOR.dtd.$captionBlock[ block.getName() ] )
      +			{
      +				enterBr( editor, mode, range, forceMode );
      +				return;
      +			}
      +
      +			// Determine the block element to be used.
      +			var blockTag = ( mode == CKEDITOR.ENTER_DIV ? 'div' : 'p' );
      +
      +			// Split the range.
      +			var splitInfo = range.splitBlock( blockTag );
      +
      +			if ( !splitInfo )
      +				return;
      +
      +			// Get the current blocks.
      +			var previousBlock	= splitInfo.previousBlock,
      +				nextBlock		= splitInfo.nextBlock;
      +
      +			var isStartOfBlock	= splitInfo.wasStartOfBlock,
      +				isEndOfBlock	= splitInfo.wasEndOfBlock;
      +
      +			var node;
      +
      +			// If this is a block under a list item, split it as well. (#1647)
      +			if ( nextBlock )
      +			{
      +				node = nextBlock.getParent();
      +				if ( node.is( 'li' ) )
      +				{
      +					nextBlock.breakParent( node );
      +					nextBlock.move( nextBlock.getNext(), 1 );
      +				}
      +			}
      +			else if ( previousBlock && ( node = previousBlock.getParent() ) && node.is( 'li' ) )
      +			{
      +				previousBlock.breakParent( node );
      +				node = previousBlock.getNext();
      +				range.moveToElementEditStart( node );
      +				previousBlock.move( previousBlock.getPrevious() );
      +			}
      +
      +			// If we have both the previous and next blocks, it means that the
      +			// boundaries were on separated blocks, or none of them where on the
      +			// block limits (start/end).
      +			if ( !isStartOfBlock && !isEndOfBlock )
      +			{
      +				// If the next block is an 
    4. with another list tree as the first + // child, we'll need to append a filler (
      /NBSP) or the list item + // wouldn't be editable. (#1420) + if ( nextBlock.is( 'li' ) + && ( node = nextBlock.getFirst( CKEDITOR.dom.walker.invisible( true ) ) ) + && node.is && node.is( 'ul', 'ol' ) ) + ( CKEDITOR.env.ie ? doc.createText( '\xa0' ) : doc.createElement( 'br' ) ).insertBefore( node ); + + // Move the selection to the end block. + if ( nextBlock ) + range.moveToElementEditStart( nextBlock ); + } + else + { + var newBlock, + newBlockDir; + + if ( previousBlock ) + { + // Do not enter this block if it's a header tag, or we are in + // a Shift+Enter (#77). Create a new block element instead + // (later in the code). + if ( previousBlock.is( 'li' ) || + ! ( headerTagRegex.test( previousBlock.getName() ) || previousBlock.is( 'pre' ) ) ) + { + // Otherwise, duplicate the previous block. + newBlock = previousBlock.clone(); + } + } + else if ( nextBlock ) + newBlock = nextBlock.clone(); + + if ( !newBlock ) + { + // We have already created a new list item. (#6849) + if ( node && node.is( 'li' ) ) + newBlock = node; + else + { + newBlock = doc.createElement( blockTag ); + if ( previousBlock && ( newBlockDir = previousBlock.getDirection() ) ) + newBlock.setAttribute( 'dir', newBlockDir ); + } + } + // Force the enter block unless we're talking of a list item. + else if ( forceMode && !newBlock.is( 'li' ) ) + newBlock.renameNode( blockTag ); + + // Recreate the inline elements tree, which was available + // before hitting enter, so the same styles will be available in + // the new block. + var elementPath = splitInfo.elementPath; + if ( elementPath ) + { + for ( var i = 0, len = elementPath.elements.length ; i < len ; i++ ) + { + var element = elementPath.elements[ i ]; + + if ( element.equals( elementPath.block ) || element.equals( elementPath.blockLimit ) ) + break; + + if ( CKEDITOR.dtd.$removeEmpty[ element.getName() ] ) + { + element = element.clone(); + newBlock.moveChildren( element ); + newBlock.append( element ); + } + } + } + + if ( !CKEDITOR.env.ie ) + newBlock.appendBogus(); + + if ( !newBlock.getParent() ) + range.insertNode( newBlock ); + + // list item start number should not be duplicated (#7330), but we need + // to remove the attribute after it's onto the DOM tree because of old IEs (#7581). + newBlock.is( 'li' ) && newBlock.removeAttribute( 'value' ); + + // This is tricky, but to make the new block visible correctly + // we must select it. + // The previousBlock check has been included because it may be + // empty if we have fixed a block-less space (like ENTER into an + // empty table cell). + if ( CKEDITOR.env.ie && isStartOfBlock && ( !isEndOfBlock || !previousBlock.getChildCount() ) ) + { + // Move the selection to the new block. + range.moveToElementEditStart( isEndOfBlock ? previousBlock : newBlock ); + range.select(); + } + + // Move the selection to the new block. + range.moveToElementEditStart( isStartOfBlock && !isEndOfBlock ? nextBlock : newBlock ); + } + + if ( !CKEDITOR.env.ie ) + { + if ( nextBlock ) + { + // If we have split the block, adds a temporary span at the + // range position and scroll relatively to it. + var tmpNode = doc.createElement( 'span' ); + + // We need some content for Safari. + tmpNode.setHtml( ' ' ); + + range.insertNode( tmpNode ); + tmpNode.scrollIntoView(); + range.deleteContents(); + } + else + { + // We may use the above scroll logic for the new block case + // too, but it gives some weird result with Opera. + newBlock.scrollIntoView(); + } + } + + range.select(); + }, + + enterBr : function( editor, mode, range, forceMode ) + { + // Get the range for the current selection. + range = range || getRange( editor ); + + // We may not have valid ranges to work on, like when inside a + // contenteditable=false element. + if ( !range ) + return; + + var doc = range.document; + + // Determine the block element to be used. + var blockTag = ( mode == CKEDITOR.ENTER_DIV ? 'div' : 'p' ); + + var isEndOfBlock = range.checkEndOfBlock(); + + var elementPath = new CKEDITOR.dom.elementPath( editor.getSelection().getStartElement() ); + + var startBlock = elementPath.block, + startBlockTag = startBlock && elementPath.block.getName(); + + var isPre = false; + + if ( !forceMode && startBlockTag == 'li' ) + { + enterBlock( editor, mode, range, forceMode ); + return; + } + + // If we are at the end of a header block. + if ( !forceMode && isEndOfBlock && headerTagRegex.test( startBlockTag ) ) + { + var newBlock, + newBlockDir; + + if ( ( newBlockDir = startBlock.getDirection() ) ) + { + newBlock = doc.createElement( 'div' ); + newBlock.setAttribute( 'dir', newBlockDir ); + newBlock.insertAfter( startBlock ); + range.setStart( newBlock, 0 ); + } + else + { + // Insert a
      after the current paragraph. + doc.createElement( 'br' ).insertAfter( startBlock ); + + // A text node is required by Gecko only to make the cursor blink. + if ( CKEDITOR.env.gecko ) + doc.createText( '' ).insertAfter( startBlock ); + + // IE has different behaviors regarding position. + range.setStartAt( startBlock.getNext(), CKEDITOR.env.ie ? CKEDITOR.POSITION_BEFORE_START : CKEDITOR.POSITION_AFTER_START ); + } + } + else + { + var lineBreak; + + isPre = ( startBlockTag == 'pre' ); + + // Gecko prefers
      as line-break inside
       (#4711).
      +				if ( isPre && !CKEDITOR.env.gecko )
      +					lineBreak = doc.createText( CKEDITOR.env.ie ? '\r' : '\n' );
      +				else
      +					lineBreak = doc.createElement( 'br' );
      +
      +				range.deleteContents();
      +				range.insertNode( lineBreak );
      +
      +				// IE has different behavior regarding position.
      +				if ( CKEDITOR.env.ie )
      +					range.setStartAt( lineBreak, CKEDITOR.POSITION_AFTER_END );
      +				else
      +				{
      +					// A text node is required by Gecko only to make the cursor blink.
      +					// We need some text inside of it, so the bogus 
      is properly + // created. + doc.createText( '\ufeff' ).insertAfter( lineBreak ); + + // If we are at the end of a block, we must be sure the bogus node is available in that block. + if ( isEndOfBlock ) + lineBreak.getParent().appendBogus(); + + // Now we can remove the text node contents, so the caret doesn't + // stop on it. + lineBreak.getNext().$.nodeValue = ''; + + range.setStartAt( lineBreak.getNext(), CKEDITOR.POSITION_AFTER_START ); + + // Scroll into view, for non IE. + var dummy = null; + + // BR is not positioned in Opera and Webkit. + if ( !CKEDITOR.env.gecko ) + { + dummy = doc.createElement( 'span' ); + // We need have some contents for Webkit to position it + // under parent node. ( #3681) + dummy.setHtml(' '); + } + else + dummy = doc.createElement( 'br' ); + + dummy.insertBefore( lineBreak.getNext() ); + dummy.scrollIntoView(); + dummy.remove(); + } + } + + // This collapse guarantees the cursor will be blinking. + range.collapse( true ); + + range.select( isPre ); + } + }; + + var plugin = CKEDITOR.plugins.enterkey, + enterBr = plugin.enterBr, + enterBlock = plugin.enterBlock, + headerTagRegex = /^h[1-6]$/; + + function shiftEnter( editor ) + { + // Only effective within document. + if ( editor.mode != 'wysiwyg' ) + return false; + + // On SHIFT+ENTER: + // 1. We want to enforce the mode to be respected, instead + // of cloning the current block. (#77) + return enter( editor, editor.config.shiftEnterMode, 1 ); + } + + function enter( editor, mode, forceMode ) + { + forceMode = editor.config.forceEnterMode || forceMode; + + // Only effective within document. + if ( editor.mode != 'wysiwyg' ) + return false; + + if ( !mode ) + mode = editor.config.enterMode; + + // Use setTimout so the keys get cancelled immediatelly. + setTimeout( function() + { + editor.fire( 'saveSnapshot' ); // Save undo step. + + if ( mode == CKEDITOR.ENTER_BR ) + enterBr( editor, mode, null, forceMode ); + else + enterBlock( editor, mode, null, forceMode ); + + editor.fire( 'saveSnapshot' ); + + }, 0 ); + + return true; + } + + function getRange( editor ) + { + // Get the selection ranges. + var ranges = editor.getSelection().getRanges( true ); + + // Delete the contents of all ranges except the first one. + for ( var i = ranges.length - 1 ; i > 0 ; i-- ) + { + ranges[ i ].deleteContents(); + } + + // Return the first range. + return ranges[ 0 ]; + } +})(); Index: 3rdParty_sources/ckeditor/plugins/entities/plugin.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/plugins/entities/plugin.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/plugins/entities/plugin.js 17 Aug 2012 14:15:52 -0000 1.1 @@ -0,0 +1,250 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +(function() +{ + // Base HTML entities. + var htmlbase = 'nbsp,gt,lt,amp'; + + var entities = + // Latin-1 Entities + 'quot,iexcl,cent,pound,curren,yen,brvbar,sect,uml,copy,ordf,laquo,' + + 'not,shy,reg,macr,deg,plusmn,sup2,sup3,acute,micro,para,middot,' + + 'cedil,sup1,ordm,raquo,frac14,frac12,frac34,iquest,times,divide,' + + + // Symbols + 'fnof,bull,hellip,prime,Prime,oline,frasl,weierp,image,real,trade,' + + 'alefsym,larr,uarr,rarr,darr,harr,crarr,lArr,uArr,rArr,dArr,hArr,' + + 'forall,part,exist,empty,nabla,isin,notin,ni,prod,sum,minus,lowast,' + + 'radic,prop,infin,ang,and,or,cap,cup,int,there4,sim,cong,asymp,ne,' + + 'equiv,le,ge,sub,sup,nsub,sube,supe,oplus,otimes,perp,sdot,lceil,' + + 'rceil,lfloor,rfloor,lang,rang,loz,spades,clubs,hearts,diams,' + + + // Other Special Characters + 'circ,tilde,ensp,emsp,thinsp,zwnj,zwj,lrm,rlm,ndash,mdash,lsquo,' + + 'rsquo,sbquo,ldquo,rdquo,bdquo,dagger,Dagger,permil,lsaquo,rsaquo,' + + 'euro'; + + // Latin Letters Entities + var latin = + 'Agrave,Aacute,Acirc,Atilde,Auml,Aring,AElig,Ccedil,Egrave,Eacute,' + + 'Ecirc,Euml,Igrave,Iacute,Icirc,Iuml,ETH,Ntilde,Ograve,Oacute,Ocirc,' + + 'Otilde,Ouml,Oslash,Ugrave,Uacute,Ucirc,Uuml,Yacute,THORN,szlig,' + + 'agrave,aacute,acirc,atilde,auml,aring,aelig,ccedil,egrave,eacute,' + + 'ecirc,euml,igrave,iacute,icirc,iuml,eth,ntilde,ograve,oacute,ocirc,' + + 'otilde,ouml,oslash,ugrave,uacute,ucirc,uuml,yacute,thorn,yuml,' + + 'OElig,oelig,Scaron,scaron,Yuml'; + + // Greek Letters Entities. + var greek = + 'Alpha,Beta,Gamma,Delta,Epsilon,Zeta,Eta,Theta,Iota,Kappa,Lambda,Mu,' + + 'Nu,Xi,Omicron,Pi,Rho,Sigma,Tau,Upsilon,Phi,Chi,Psi,Omega,alpha,' + + 'beta,gamma,delta,epsilon,zeta,eta,theta,iota,kappa,lambda,mu,nu,xi,' + + 'omicron,pi,rho,sigmaf,sigma,tau,upsilon,phi,chi,psi,omega,thetasym,' + + 'upsih,piv'; + + /** + * Create a mapping table between one character and its entity form from a list of entity names. + * @param reverse {Boolean} Whether to create a reverse map from the entity string form to an actual character. + */ + function buildTable( entities, reverse ) + { + var table = {}, + regex = []; + + // Entities that the browsers DOM don't transform to the final char + // automatically. + var specialTable = + { + nbsp : '\u00A0', // IE | FF + shy : '\u00AD', // IE + gt : '\u003E', // IE | FF | -- | Opera + lt : '\u003C', // IE | FF | Safari | Opera + amp : '\u0026' // ALL + }; + + entities = entities.replace( /\b(nbsp|shy|gt|lt|amp)(?:,|$)/g, function( match, entity ) + { + var org = reverse ? '&' + entity + ';' : specialTable[ entity ], + result = reverse ? specialTable[ entity ] : '&' + entity + ';'; + + table[ org ] = result; + regex.push( org ); + return ''; + }); + + if ( !reverse && entities ) + { + // Transforms the entities string into an array. + entities = entities.split( ',' ); + + // Put all entities inside a DOM element, transforming them to their + // final chars. + var div = document.createElement( 'div' ), + chars; + div.innerHTML = '&' + entities.join( ';&' ) + ';'; + chars = div.innerHTML; + div = null; + + // Add all chars to the table. + for ( var i = 0 ; i < chars.length ; i++ ) + { + var charAt = chars.charAt( i ); + table[ charAt ] = '&' + entities[ i ] + ';'; + regex.push( charAt ); + } + } + + table.regex = regex.join( reverse ? '|' : '' ); + + return table; + } + + CKEDITOR.plugins.add( 'entities', + { + afterInit : function( editor ) + { + var config = editor.config; + + var dataProcessor = editor.dataProcessor, + htmlFilter = dataProcessor && dataProcessor.htmlFilter; + + if ( htmlFilter ) + { + // Mandatory HTML base entities. + var selectedEntities = ''; + + if ( config.basicEntities !== false ) + selectedEntities += htmlbase; + + if ( config.entities ) + { + selectedEntities += ',' + entities; + if ( config.entities_latin ) + selectedEntities += ',' + latin; + + if ( config.entities_greek ) + selectedEntities += ',' + greek; + + if ( config.entities_additional ) + selectedEntities += ',' + config.entities_additional; + } + + var entitiesTable = buildTable( selectedEntities ); + + // Create the Regex used to find entities in the text, leave it matches nothing if entities are empty. + var entitiesRegex = entitiesTable.regex ? '[' + entitiesTable.regex + ']' : 'a^'; + delete entitiesTable.regex; + + if ( config.entities && config.entities_processNumerical ) + entitiesRegex = '[^ -~]|' + entitiesRegex ; + + entitiesRegex = new RegExp( entitiesRegex, 'g' ); + + function getEntity( character ) + { + return config.entities_processNumerical == 'force' || !entitiesTable[ character ] ? + '&#' + character.charCodeAt(0) + ';' + : entitiesTable[ character ]; + } + + // Decode entities that the browsers has transformed + // at first place. + var baseEntitiesTable = buildTable( [ htmlbase, 'shy' ].join( ',' ) , true ), + baseEntitiesRegex = new RegExp( baseEntitiesTable.regex, 'g' ); + + function getChar( character ) + { + return baseEntitiesTable[ character ]; + } + + htmlFilter.addRules( + { + text : function( text ) + { + return text.replace( baseEntitiesRegex, getChar ) + .replace( entitiesRegex, getEntity ); + } + }); + } + } + }); +})(); + +/** + * Whether to escape basic HTML entities in the document, including: + *
        + *
      • nbsp
      • + *
      • gt
      • + *
      • lt
      • + *
      • amp
      • + *
      + * Note: It should not be subject to change unless when outputting a non-HTML data format like BBCode. + * @type Boolean + * @default true + * @example + * config.basicEntities = false; + */ +CKEDITOR.config.basicEntities = true; + +/** + * Whether to use HTML entities in the output. + * @name CKEDITOR.config.entities + * @type Boolean + * @default true + * @example + * config.entities = false; + */ +CKEDITOR.config.entities = true; + +/** + * Whether to convert some Latin characters (Latin alphabet No. 1, ISO 8859-1) + * to HTML entities. The list of entities can be found in the + * W3C HTML 4.01 Specification, section 24.2.1. + * @name CKEDITOR.config.entities_latin + * @type Boolean + * @default true + * @example + * config.entities_latin = false; + */ +CKEDITOR.config.entities_latin = true; + +/** + * Whether to convert some symbols, mathematical symbols, and Greek letters to + * HTML entities. This may be more relevant for users typing text written in Greek. + * The list of entities can be found in the + * W3C HTML 4.01 Specification, section 24.3.1. + * @name CKEDITOR.config.entities_greek + * @type Boolean + * @default true + * @example + * config.entities_greek = false; + */ +CKEDITOR.config.entities_greek = true; + +/** + * Whether to convert all remaining characters not included in the ASCII + * character table to their relative decimal numeric representation of HTML entity. + * When set to force, it will convert all entities into this format. + * For example the phrase "This is Chinese: 汉语." is output + * as "This is Chinese: &#27721;&#35821;." + * @name CKEDITOR.config.entities_processNumerical + * @type Boolean|String + * @default false + * @example + * config.entities_processNumerical = true; + * config.entities_processNumerical = 'force'; //Converts from " " into " "; + */ + +/** + * A comma separated list of additional entities to be used. Entity names + * or numbers must be used in a form that excludes the "&" prefix and the ";" ending. + * @name CKEDITOR.config.entities_additional + * @default '#39' (The single quote (') character.) + * @type String + * @example + * config.entities_additional = '#1049'; // Adds Cyrillic capital letter Short I (Й). + */ +CKEDITOR.config.entities_additional = '#39'; Index: 3rdParty_sources/ckeditor/plugins/fakeobjects/plugin.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/plugins/fakeobjects/plugin.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/plugins/fakeobjects/plugin.js 17 Aug 2012 14:15:50 -0000 1.1 @@ -0,0 +1,175 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +(function() +{ + var cssStyle = CKEDITOR.htmlParser.cssStyle, + cssLength = CKEDITOR.tools.cssLength; + + var cssLengthRegex = /^((?:\d*(?:\.\d+))|(?:\d+))(.*)?$/i; + + /* + * Replacing the former CSS length value with the later one, with + * adjustment to the length unit. + */ + function replaceCssLength( length1, length2 ) + { + var parts1 = cssLengthRegex.exec( length1 ), + parts2 = cssLengthRegex.exec( length2 ); + + // Omit pixel length unit when necessary, + // e.g. replaceCssLength( 10, '20px' ) -> 20 + if ( parts1 ) + { + if ( !parts1[ 2 ] && parts2[ 2 ] == 'px' ) + return parts2[ 1 ]; + if ( parts1[ 2 ] == 'px' && !parts2[ 2 ] ) + return parts2[ 1 ] + 'px'; + } + + return length2; + } + + var htmlFilterRules = + { + elements : + { + $ : function( element ) + { + var attributes = element.attributes, + realHtml = attributes && attributes[ 'data-cke-realelement' ], + realFragment = realHtml && new CKEDITOR.htmlParser.fragment.fromHtml( decodeURIComponent( realHtml ) ), + realElement = realFragment && realFragment.children[ 0 ]; + + // Width/height in the fake object are subjected to clone into the real element. + if ( realElement && element.attributes[ 'data-cke-resizable' ] ) + { + var styles = new cssStyle( element ).rules, + realAttrs = realElement.attributes, + width = styles.width, + height = styles.height; + + width && ( realAttrs.width = replaceCssLength( realAttrs.width, width ) ); + height && ( realAttrs.height = replaceCssLength( realAttrs.height, height ) ); + } + + return realElement; + } + } + }; + + CKEDITOR.plugins.add( 'fakeobjects', + { + requires : [ 'htmlwriter' ], + + afterInit : function( editor ) + { + var dataProcessor = editor.dataProcessor, + htmlFilter = dataProcessor && dataProcessor.htmlFilter; + + if ( htmlFilter ) + htmlFilter.addRules( htmlFilterRules ); + } + }); + + CKEDITOR.editor.prototype.createFakeElement = function( realElement, className, realElementType, isResizable ) + { + var lang = this.lang.fakeobjects, + label = lang[ realElementType ] || lang.unknown; + + var attributes = + { + 'class' : className, + src : CKEDITOR.getUrl( 'images/spacer.gif' ), + 'data-cke-realelement' : encodeURIComponent( realElement.getOuterHtml() ), + 'data-cke-real-node-type' : realElement.type, + alt : label, + title : label, + align : realElement.getAttribute( 'align' ) || '' + }; + + if ( realElementType ) + attributes[ 'data-cke-real-element-type' ] = realElementType; + + if ( isResizable ) + { + attributes[ 'data-cke-resizable' ] = isResizable; + + var fakeStyle = new cssStyle(); + + var width = realElement.getAttribute( 'width' ), + height = realElement.getAttribute( 'height' ); + + width && ( fakeStyle.rules.width = cssLength( width ) ); + height && ( fakeStyle.rules.height = cssLength( height ) ); + fakeStyle.populate( attributes ); + } + + return this.document.createElement( 'img', { attributes : attributes } ); + }; + + CKEDITOR.editor.prototype.createFakeParserElement = function( realElement, className, realElementType, isResizable ) + { + var lang = this.lang.fakeobjects, + label = lang[ realElementType ] || lang.unknown, + html; + + var writer = new CKEDITOR.htmlParser.basicWriter(); + realElement.writeHtml( writer ); + html = writer.getHtml(); + + var attributes = + { + 'class' : className, + src : CKEDITOR.getUrl( 'images/spacer.gif' ), + 'data-cke-realelement' : encodeURIComponent( html ), + 'data-cke-real-node-type' : realElement.type, + alt : label, + title : label, + align : realElement.attributes.align || '' + }; + + if ( realElementType ) + attributes[ 'data-cke-real-element-type' ] = realElementType; + + if ( isResizable ) + { + attributes[ 'data-cke-resizable' ] = isResizable; + var realAttrs = realElement.attributes, + fakeStyle = new cssStyle(); + + var width = realAttrs.width, + height = realAttrs.height; + + width != undefined && ( fakeStyle.rules.width = cssLength( width ) ); + height != undefined && ( fakeStyle.rules.height = cssLength ( height ) ); + fakeStyle.populate( attributes ); + } + + return new CKEDITOR.htmlParser.element( 'img', attributes ); + }; + + CKEDITOR.editor.prototype.restoreRealElement = function( fakeElement ) + { + if ( fakeElement.data( 'cke-real-node-type' ) != CKEDITOR.NODE_ELEMENT ) + return null; + + var element = CKEDITOR.dom.element.createFromHtml( + decodeURIComponent( fakeElement.data( 'cke-realelement' ) ), + this.document ); + + if ( fakeElement.data( 'cke-resizable') ) + { + var width = fakeElement.getStyle( 'width' ), + height = fakeElement.getStyle( 'height' ); + + width && element.setAttribute( 'width', replaceCssLength( element.getAttribute( 'width' ), width ) ); + height && element.setAttribute( 'height', replaceCssLength( element.getAttribute( 'height' ), height ) ); + } + + return element; + }; + +})(); Index: 3rdParty_sources/ckeditor/plugins/filebrowser/plugin.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/plugins/filebrowser/plugin.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/plugins/filebrowser/plugin.js 17 Aug 2012 14:15:49 -0000 1.1 @@ -0,0 +1,534 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * @fileOverview The "filebrowser" plugin that adds support for file uploads and + * browsing. + * + * When a file is uploaded or selected inside the file browser, its URL is + * inserted automatically into a field defined in the filebrowser + * attribute. In order to specify a field that should be updated, pass the tab ID and + * the element ID, separated with a colon.

      + * + * Example 1: (Browse) + * + *
      + * {
      + * 	type : 'button',
      + * 	id : 'browse',
      + * 	filebrowser : 'tabId:elementId',
      + * 	label : editor.lang.common.browseServer
      + * }
      + * 
      + * + * If you set the filebrowser attribute for an element other than + * the fileButton, the Browse action will be triggered.

      + * + * Example 2: (Quick Upload) + * + *
      + * {
      + * 	type : 'fileButton',
      + * 	id : 'uploadButton',
      + * 	filebrowser : 'tabId:elementId',
      + * 	label : editor.lang.common.uploadSubmit,
      + * 	'for' : [ 'upload', 'upload' ]
      + * }
      + * 
      + * + * If you set the filebrowser attribute for a fileButton + * element, the QuickUpload action will be executed.

      + * + * The filebrowser plugin also supports more advanced configuration performed through + * a JavaScript object. + * + * The following settings are supported: + * + *
        + *
      • actionBrowse or QuickUpload.
      • + *
      • target – the field to update in the tabId:elementId format.
      • + *
      • params – additional arguments to be passed to the server connector (optional).
      • + *
      • onSelect – a function to execute when the file is selected/uploaded (optional).
      • + *
      • url – the URL to be called (optional).
      • + *
      + * + * Example 3: (Quick Upload) + * + *
      + * {
      + * 	type : 'fileButton',
      + * 	label : editor.lang.common.uploadSubmit,
      + * 	id : 'buttonId',
      + * 	filebrowser :
      + * 	{
      + * 		action : 'QuickUpload', // required
      + * 		target : 'tab1:elementId', // required
      + * 		params : // optional
      + * 		{
      + * 			type : 'Files',
      + * 			currentFolder : '/folder/'
      + * 		},
      + * 		onSelect : function( fileUrl, errorMessage ) // optional
      + * 		{
      + * 			// Do not call the built-in selectFuntion.
      + * 			// return false;
      + * 		}
      + * 	},
      + * 	'for' : [ 'tab1', 'myFile' ]
      + * }
      + * 
      + * + * Suppose you have a file element with an ID of myFile, a text + * field with an ID of elementId and a fileButton. + * If the filebowser.url attribute is not specified explicitly, + * the form action will be set to filebrowser[DialogWindowName]UploadUrl + * or, if not specified, to filebrowserUploadUrl. Additional parameters + * from the params object will be added to the query string. It is + * possible to create your own uploadHandler and cancel the built-in + * updateTargetElement command.

      + * + * Example 4: (Browse) + * + *
      + * {
      + * 	type : 'button',
      + * 	id : 'buttonId',
      + * 	label : editor.lang.common.browseServer,
      + * 	filebrowser :
      + * 	{
      + * 		action : 'Browse',
      + * 		url : '/ckfinder/ckfinder.html&type=Images',
      + * 		target : 'tab1:elementId'
      + * 	}
      + * }
      + * 
      + * + * In this example, when the button is pressed, the file browser will be opened in a + * popup window. If you do not specify the filebrowser.url attribute, + * filebrowser[DialogName]BrowseUrl or + * filebrowserBrowseUrl will be used. After selecting a file in the file + * browser, an element with an ID of elementId will be updated. Just + * like in the third example, a custom onSelect function may be defined. + */ +( function() +{ + /* + * Adds (additional) arguments to given url. + * + * @param {String} + * url The url. + * @param {Object} + * params Additional parameters. + */ + function addQueryString( url, params ) + { + var queryString = []; + + if ( !params ) + return url; + else + { + for ( var i in params ) + queryString.push( i + "=" + encodeURIComponent( params[ i ] ) ); + } + + return url + ( ( url.indexOf( "?" ) != -1 ) ? "&" : "?" ) + queryString.join( "&" ); + } + + /* + * Make a string's first character uppercase. + * + * @param {String} + * str String. + */ + function ucFirst( str ) + { + str += ''; + var f = str.charAt( 0 ).toUpperCase(); + return f + str.substr( 1 ); + } + + /* + * The onlick function assigned to the 'Browse Server' button. Opens the + * file browser and updates target field when file is selected. + * + * @param {CKEDITOR.event} + * evt The event object. + */ + function browseServer( evt ) + { + var dialog = this.getDialog(); + var editor = dialog.getParentEditor(); + + editor._.filebrowserSe = this; + + var width = editor.config[ 'filebrowser' + ucFirst( dialog.getName() ) + 'WindowWidth' ] + || editor.config.filebrowserWindowWidth || '80%'; + var height = editor.config[ 'filebrowser' + ucFirst( dialog.getName() ) + 'WindowHeight' ] + || editor.config.filebrowserWindowHeight || '70%'; + + var params = this.filebrowser.params || {}; + params.CKEditor = editor.name; + params.CKEditorFuncNum = editor._.filebrowserFn; + if ( !params.langCode ) + params.langCode = editor.langCode; + + var url = addQueryString( this.filebrowser.url, params ); + // TODO: V4: Remove backward compatibility (#8163). + editor.popup( url, width, height, editor.config.filebrowserWindowFeatures || editor.config.fileBrowserWindowFeatures ); + } + + /* + * The onlick function assigned to the 'Upload' button. Makes the final + * decision whether form is really submitted and updates target field when + * file is uploaded. + * + * @param {CKEDITOR.event} + * evt The event object. + */ + function uploadFile( evt ) + { + var dialog = this.getDialog(); + var editor = dialog.getParentEditor(); + + editor._.filebrowserSe = this; + + // If user didn't select the file, stop the upload. + if ( !dialog.getContentElement( this[ 'for' ][ 0 ], this[ 'for' ][ 1 ] ).getInputElement().$.value ) + return false; + + if ( !dialog.getContentElement( this[ 'for' ][ 0 ], this[ 'for' ][ 1 ] ).getAction() ) + return false; + + return true; + } + + /* + * Setups the file element. + * + * @param {CKEDITOR.ui.dialog.file} + * fileInput The file element used during file upload. + * @param {Object} + * filebrowser Object containing filebrowser settings assigned to + * the fileButton associated with this file element. + */ + function setupFileElement( editor, fileInput, filebrowser ) + { + var params = filebrowser.params || {}; + params.CKEditor = editor.name; + params.CKEditorFuncNum = editor._.filebrowserFn; + if ( !params.langCode ) + params.langCode = editor.langCode; + + fileInput.action = addQueryString( filebrowser.url, params ); + fileInput.filebrowser = filebrowser; + } + + /* + * Traverse through the content definition and attach filebrowser to + * elements with 'filebrowser' attribute. + * + * @param String + * dialogName Dialog name. + * @param {CKEDITOR.dialog.definitionObject} + * definition Dialog definition. + * @param {Array} + * elements Array of {@link CKEDITOR.dialog.definition.content} + * objects. + */ + function attachFileBrowser( editor, dialogName, definition, elements ) + { + var element, fileInput; + + for ( var i in elements ) + { + element = elements[ i ]; + + if ( element.type == 'hbox' || element.type == 'vbox' ) + attachFileBrowser( editor, dialogName, definition, element.children ); + + if ( !element.filebrowser ) + continue; + + if ( typeof element.filebrowser == 'string' ) + { + var fb = + { + action : ( element.type == 'fileButton' ) ? 'QuickUpload' : 'Browse', + target : element.filebrowser + }; + element.filebrowser = fb; + } + + if ( element.filebrowser.action == 'Browse' ) + { + var url = element.filebrowser.url; + if ( url === undefined ) + { + url = editor.config[ 'filebrowser' + ucFirst( dialogName ) + 'BrowseUrl' ]; + if ( url === undefined ) + url = editor.config.filebrowserBrowseUrl; + } + + if ( url ) + { + element.onClick = browseServer; + element.filebrowser.url = url; + element.hidden = false; + } + } + else if ( element.filebrowser.action == 'QuickUpload' && element[ 'for' ] ) + { + url = element.filebrowser.url; + if ( url === undefined ) + { + url = editor.config[ 'filebrowser' + ucFirst( dialogName ) + 'UploadUrl' ]; + if ( url === undefined ) + url = editor.config.filebrowserUploadUrl; + } + + if ( url ) + { + var onClick = element.onClick; + element.onClick = function( evt ) + { + // "element" here means the definition object, so we need to find the correct + // button to scope the event call + var sender = evt.sender; + if ( onClick && onClick.call( sender, evt ) === false ) + return false; + + return uploadFile.call( sender, evt ); + }; + + element.filebrowser.url = url; + element.hidden = false; + setupFileElement( editor, definition.getContents( element[ 'for' ][ 0 ] ).get( element[ 'for' ][ 1 ] ), element.filebrowser ); + } + } + } + } + + /* + * Updates the target element with the url of uploaded/selected file. + * + * @param {String} + * url The url of a file. + */ + function updateTargetElement( url, sourceElement ) + { + var dialog = sourceElement.getDialog(); + var targetElement = sourceElement.filebrowser.target || null; + url = url.replace( /#/g, '%23' ); + + // If there is a reference to targetElement, update it. + if ( targetElement ) + { + var target = targetElement.split( ':' ); + var element = dialog.getContentElement( target[ 0 ], target[ 1 ] ); + if ( element ) + { + element.setValue( url ); + dialog.selectPage( target[ 0 ] ); + } + } + } + + /* + * Returns true if filebrowser is configured in one of the elements. + * + * @param {CKEDITOR.dialog.definitionObject} + * definition Dialog definition. + * @param String + * tabId The tab id where element(s) can be found. + * @param String + * elementId The element id (or ids, separated with a semicolon) to check. + */ + function isConfigured( definition, tabId, elementId ) + { + if ( elementId.indexOf( ";" ) !== -1 ) + { + var ids = elementId.split( ";" ); + for ( var i = 0 ; i < ids.length ; i++ ) + { + if ( isConfigured( definition, tabId, ids[i] ) ) + return true; + } + return false; + } + + var elementFileBrowser = definition.getContents( tabId ).get( elementId ).filebrowser; + return ( elementFileBrowser && elementFileBrowser.url ); + } + + function setUrl( fileUrl, data ) + { + var dialog = this._.filebrowserSe.getDialog(), + targetInput = this._.filebrowserSe[ 'for' ], + onSelect = this._.filebrowserSe.filebrowser.onSelect; + + if ( targetInput ) + dialog.getContentElement( targetInput[ 0 ], targetInput[ 1 ] ).reset(); + + if ( typeof data == 'function' && data.call( this._.filebrowserSe ) === false ) + return; + + if ( onSelect && onSelect.call( this._.filebrowserSe, fileUrl, data ) === false ) + return; + + // The "data" argument may be used to pass the error message to the editor. + if ( typeof data == 'string' && data ) + alert( data ); + + if ( fileUrl ) + updateTargetElement( fileUrl, this._.filebrowserSe ); + } + + CKEDITOR.plugins.add( 'filebrowser', + { + init : function( editor, pluginPath ) + { + editor._.filebrowserFn = CKEDITOR.tools.addFunction( setUrl, editor ); + editor.on( 'destroy', function () { CKEDITOR.tools.removeFunction( this._.filebrowserFn ); } ); + } + } ); + + CKEDITOR.on( 'dialogDefinition', function( evt ) + { + var definition = evt.data.definition, + element; + // Associate filebrowser to elements with 'filebrowser' attribute. + for ( var i in definition.contents ) + { + if ( ( element = definition.contents[ i ] ) ) + { + attachFileBrowser( evt.editor, evt.data.name, definition, element.elements ); + if ( element.hidden && element.filebrowser ) + { + element.hidden = !isConfigured( definition, element[ 'id' ], element.filebrowser ); + } + } + } + } ); + +} )(); + +/** + * The location of an external file browser that should be launched when the Browse Server + * button is pressed. If configured, the Browse Server button will appear in the + * Link, Image, and Flash dialog windows. + * @see The File Browser/Uploader documentation. + * @name CKEDITOR.config.filebrowserBrowseUrl + * @since 3.0 + * @type String + * @default '' (empty string = disabled) + * @example + * config.filebrowserBrowseUrl = '/browser/browse.php'; + */ + +/** + * The location of the script that handles file uploads. + * If set, the Upload tab will appear in the Link, Image, + * and Flash dialog windows. + * @name CKEDITOR.config.filebrowserUploadUrl + * @see The File Browser/Uploader documentation. + * @since 3.0 + * @type String + * @default '' (empty string = disabled) + * @example + * config.filebrowserUploadUrl = '/uploader/upload.php'; + */ + +/** + * The location of an external file browser that should be launched when the Browse Server + * button is pressed in the Image dialog window. + * If not set, CKEditor will use {@link CKEDITOR.config.filebrowserBrowseUrl}. + * @name CKEDITOR.config.filebrowserImageBrowseUrl + * @since 3.0 + * @type String + * @default '' (empty string = disabled) + * @example + * config.filebrowserImageBrowseUrl = '/browser/browse.php?type=Images'; + */ + +/** + * The location of an external file browser that should be launched when the Browse Server + * button is pressed in the Flash dialog window. + * If not set, CKEditor will use {@link CKEDITOR.config.filebrowserBrowseUrl}. + * @name CKEDITOR.config.filebrowserFlashBrowseUrl + * @since 3.0 + * @type String + * @default '' (empty string = disabled) + * @example + * config.filebrowserFlashBrowseUrl = '/browser/browse.php?type=Flash'; + */ + +/** + * The location of the script that handles file uploads in the Image dialog window. + * If not set, CKEditor will use {@link CKEDITOR.config.filebrowserUploadUrl}. + * @name CKEDITOR.config.filebrowserImageUploadUrl + * @since 3.0 + * @type String + * @default '' (empty string = disabled) + * @example + * config.filebrowserImageUploadUrl = '/uploader/upload.php?type=Images'; + */ + +/** + * The location of the script that handles file uploads in the Flash dialog window. + * If not set, CKEditor will use {@link CKEDITOR.config.filebrowserUploadUrl}. + * @name CKEDITOR.config.filebrowserFlashUploadUrl + * @since 3.0 + * @type String + * @default '' (empty string = disabled) + * @example + * config.filebrowserFlashUploadUrl = '/uploader/upload.php?type=Flash'; + */ + +/** + * The location of an external file browser that should be launched when the Browse Server + * button is pressed in the Link tab of the Image dialog window. + * If not set, CKEditor will use {@link CKEDITOR.config.filebrowserBrowseUrl}. + * @name CKEDITOR.config.filebrowserImageBrowseLinkUrl + * @since 3.2 + * @type String + * @default '' (empty string = disabled) + * @example + * config.filebrowserImageBrowseLinkUrl = '/browser/browse.php'; + */ + +/** + * The features to use in the file browser popup window. + * @name CKEDITOR.config.filebrowserWindowFeatures + * @since 3.4.1 + * @type String + * @default 'location=no,menubar=no,toolbar=no,dependent=yes,minimizable=no,modal=yes,alwaysRaised=yes,resizable=yes,scrollbars=yes' + * @example + * config.filebrowserWindowFeatures = 'resizable=yes,scrollbars=no'; + */ + +/** + * The width of the file browser popup window. It can be a number denoting a value in + * pixels or a percent string. + * @name CKEDITOR.config.filebrowserWindowWidth + * @type Number|String + * @default '80%' + * @example + * config.filebrowserWindowWidth = 750; + * @example + * config.filebrowserWindowWidth = '50%'; + */ + +/** + * The height of the file browser popup window. It can be a number denoting a value in + * pixels or a percent string. + * @name CKEDITOR.config.filebrowserWindowHeight + * @type Number|String + * @default '70%' + * @example + * config.filebrowserWindowHeight = 580; + * @example + * config.filebrowserWindowHeight = '50%'; + */ Index: 3rdParty_sources/ckeditor/plugins/find/plugin.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/plugins/find/plugin.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/plugins/find/plugin.js 17 Aug 2012 14:15:46 -0000 1.1 @@ -0,0 +1,47 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +CKEDITOR.plugins.add( 'find', +{ + init : function( editor ) + { + var forms = CKEDITOR.plugins.find; + editor.ui.addButton( 'Find', + { + label : editor.lang.findAndReplace.find, + command : 'find' + }); + var findCommand = editor.addCommand( 'find', new CKEDITOR.dialogCommand( 'find' ) ); + findCommand.canUndo = false; + findCommand.readOnly = 1; + + editor.ui.addButton( 'Replace', + { + label : editor.lang.findAndReplace.replace, + command : 'replace' + }); + var replaceCommand = editor.addCommand( 'replace', new CKEDITOR.dialogCommand( 'replace' ) ); + replaceCommand.canUndo = false; + + CKEDITOR.dialog.add( 'find', this.path + 'dialogs/find.js' ); + CKEDITOR.dialog.add( 'replace', this.path + 'dialogs/find.js' ); + }, + + requires : [ 'styles' ] +} ); + +/** + * Defines the style to be used to highlight results with the find dialog. + * @type Object + * @default { element : 'span', styles : { 'background-color' : '#004', 'color' : '#fff' } } + * @example + * // Highlight search results with blue on yellow. + * config.find_highlight = + * { + * element : 'span', + * styles : { 'background-color' : '#ff0', 'color' : '#00f' } + * }; + */ +CKEDITOR.config.find_highlight = { element : 'span', styles : { 'background-color' : '#004', 'color' : '#fff' } }; Index: 3rdParty_sources/ckeditor/plugins/find/dialogs/find.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/plugins/find/dialogs/find.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/plugins/find/dialogs/find.js 17 Aug 2012 14:15:46 -0000 1.1 @@ -0,0 +1,915 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +(function() +{ + var isReplace; + + function findEvaluator( node ) + { + return node.type == CKEDITOR.NODE_TEXT && node.getLength() > 0 && ( !isReplace || !node.isReadOnly() ); + } + + /** + * Elements which break characters been considered as sequence. + */ + function nonCharactersBoundary( node ) + { + return !( node.type == CKEDITOR.NODE_ELEMENT && node.isBlockBoundary( + CKEDITOR.tools.extend( {}, CKEDITOR.dtd.$empty, CKEDITOR.dtd.$nonEditable ) ) ); + } + + /** + * Get the cursor object which represent both current character and it's dom + * position thing. + */ + var cursorStep = function() + { + return { + textNode : this.textNode, + offset : this.offset, + character : this.textNode ? + this.textNode.getText().charAt( this.offset ) : null, + hitMatchBoundary : this._.matchBoundary + }; + }; + + var pages = [ 'find', 'replace' ], + fieldsMapping = [ + [ 'txtFindFind', 'txtFindReplace' ], + [ 'txtFindCaseChk', 'txtReplaceCaseChk' ], + [ 'txtFindWordChk', 'txtReplaceWordChk' ], + [ 'txtFindCyclic', 'txtReplaceCyclic' ] ]; + + /** + * Synchronize corresponding filed values between 'replace' and 'find' pages. + * @param {String} currentPageId The page id which receive values. + */ + function syncFieldsBetweenTabs( currentPageId ) + { + var sourceIndex, targetIndex, + sourceField, targetField; + + sourceIndex = currentPageId === 'find' ? 1 : 0; + targetIndex = 1 - sourceIndex; + var i, l = fieldsMapping.length; + for ( i = 0 ; i < l ; i++ ) + { + sourceField = this.getContentElement( pages[ sourceIndex ], + fieldsMapping[ i ][ sourceIndex ] ); + targetField = this.getContentElement( pages[ targetIndex ], + fieldsMapping[ i ][ targetIndex ] ); + + targetField.setValue( sourceField.getValue() ); + } + } + + var findDialog = function( editor, startupPage ) + { + // Style object for highlights: (#5018) + // 1. Defined as full match style to avoid compromising ordinary text color styles. + // 2. Must be apply onto inner-most text to avoid conflicting with ordinary text color styles visually. + var highlightStyle = new CKEDITOR.style( + CKEDITOR.tools.extend( { attributes : { 'data-cke-highlight': 1 }, fullMatch : 1, ignoreReadonly : 1, childRule : function(){ return 0; } }, + editor.config.find_highlight, true ) ); + + /** + * Iterator which walk through the specified range char by char. By + * default the walking will not stop at the character boundaries, until + * the end of the range is encountered. + * @param { CKEDITOR.dom.range } range + * @param {Boolean} matchWord Whether the walking will stop at character boundary. + */ + var characterWalker = function( range , matchWord ) + { + var self = this; + var walker = + new CKEDITOR.dom.walker( range ); + walker.guard = matchWord ? nonCharactersBoundary : function( node ) + { + !nonCharactersBoundary( node ) && ( self._.matchBoundary = true ); + }; + walker[ 'evaluator' ] = findEvaluator; + walker.breakOnFalse = 1; + + if ( range.startContainer.type == CKEDITOR.NODE_TEXT ) + { + this.textNode = range.startContainer; + this.offset = range.startOffset - 1; + } + + this._ = { + matchWord : matchWord, + walker : walker, + matchBoundary : false + }; + }; + + characterWalker.prototype = { + next : function() + { + return this.move(); + }, + + back : function() + { + return this.move( true ); + }, + + move : function( rtl ) + { + var currentTextNode = this.textNode; + // Already at the end of document, no more character available. + if ( currentTextNode === null ) + return cursorStep.call( this ); + + this._.matchBoundary = false; + + // There are more characters in the text node, step forward. + if ( currentTextNode + && rtl + && this.offset > 0 ) + { + this.offset--; + return cursorStep.call( this ); + } + else if ( currentTextNode + && this.offset < currentTextNode.getLength() - 1 ) + { + this.offset++; + return cursorStep.call( this ); + } + else + { + currentTextNode = null; + // At the end of the text node, walking foward for the next. + while ( !currentTextNode ) + { + currentTextNode = + this._.walker[ rtl ? 'previous' : 'next' ].call( this._.walker ); + + // Stop searching if we're need full word match OR + // already reach document end. + if ( this._.matchWord && !currentTextNode + || this._.walker._.end ) + break; + } + // Found a fresh text node. + this.textNode = currentTextNode; + if ( currentTextNode ) + this.offset = rtl ? currentTextNode.getLength() - 1 : 0; + else + this.offset = 0; + } + + return cursorStep.call( this ); + } + + }; + + /** + * A range of cursors which represent a trunk of characters which try to + * match, it has the same length as the pattern string. + */ + var characterRange = function( characterWalker, rangeLength ) + { + this._ = { + walker : characterWalker, + cursors : [], + rangeLength : rangeLength, + highlightRange : null, + isMatched : 0 + }; + }; + + characterRange.prototype = { + /** + * Translate this range to {@link CKEDITOR.dom.range} + */ + toDomRange : function() + { + var range = new CKEDITOR.dom.range( editor.document ); + var cursors = this._.cursors; + if ( cursors.length < 1 ) + { + var textNode = this._.walker.textNode; + if ( textNode ) + range.setStartAfter( textNode ); + else + return null; + } + else + { + var first = cursors[0], + last = cursors[ cursors.length - 1 ]; + + range.setStart( first.textNode, first.offset ); + range.setEnd( last.textNode, last.offset + 1 ); + } + + return range; + }, + /** + * Reflect the latest changes from dom range. + */ + updateFromDomRange : function( domRange ) + { + var cursor, + walker = new characterWalker( domRange ); + this._.cursors = []; + do + { + cursor = walker.next(); + if ( cursor.character ) + this._.cursors.push( cursor ); + } + while ( cursor.character ); + this._.rangeLength = this._.cursors.length; + }, + + setMatched : function() + { + this._.isMatched = true; + }, + + clearMatched : function() + { + this._.isMatched = false; + }, + + isMatched : function() + { + return this._.isMatched; + }, + + /** + * Hightlight the current matched chunk of text. + */ + highlight : function() + { + // Do not apply if nothing is found. + if ( this._.cursors.length < 1 ) + return; + + // Remove the previous highlight if there's one. + if ( this._.highlightRange ) + this.removeHighlight(); + + // Apply the highlight. + var range = this.toDomRange(), + bookmark = range.createBookmark(); + highlightStyle.applyToRange( range ); + range.moveToBookmark( bookmark ); + this._.highlightRange = range; + + // Scroll the editor to the highlighted area. + var element = range.startContainer; + if ( element.type != CKEDITOR.NODE_ELEMENT ) + element = element.getParent(); + element.scrollIntoView(); + + // Update the character cursors. + this.updateFromDomRange( range ); + }, + + /** + * Remove highlighted find result. + */ + removeHighlight : function() + { + if ( !this._.highlightRange ) + return; + + var bookmark = this._.highlightRange.createBookmark(); + highlightStyle.removeFromRange( this._.highlightRange ); + this._.highlightRange.moveToBookmark( bookmark ); + this.updateFromDomRange( this._.highlightRange ); + this._.highlightRange = null; + }, + + isReadOnly : function() + { + if ( !this._.highlightRange ) + return 0; + + return this._.highlightRange.startContainer.isReadOnly(); + }, + + moveBack : function() + { + var retval = this._.walker.back(), + cursors = this._.cursors; + + if ( retval.hitMatchBoundary ) + this._.cursors = cursors = []; + + cursors.unshift( retval ); + if ( cursors.length > this._.rangeLength ) + cursors.pop(); + + return retval; + }, + + moveNext : function() + { + var retval = this._.walker.next(), + cursors = this._.cursors; + + // Clear the cursors queue if we've crossed a match boundary. + if ( retval.hitMatchBoundary ) + this._.cursors = cursors = []; + + cursors.push( retval ); + if ( cursors.length > this._.rangeLength ) + cursors.shift(); + + return retval; + }, + + getEndCharacter : function() + { + var cursors = this._.cursors; + if ( cursors.length < 1 ) + return null; + + return cursors[ cursors.length - 1 ].character; + }, + + getNextCharacterRange : function( maxLength ) + { + var lastCursor, + nextRangeWalker, + cursors = this._.cursors; + + if ( ( lastCursor = cursors[ cursors.length - 1 ] ) && lastCursor.textNode ) + nextRangeWalker = new characterWalker( getRangeAfterCursor( lastCursor ) ); + // In case it's an empty range (no cursors), figure out next range from walker (#4951). + else + nextRangeWalker = this._.walker; + + return new characterRange( nextRangeWalker, maxLength ); + }, + + getCursors : function() + { + return this._.cursors; + } + }; + + + // The remaining document range after the character cursor. + function getRangeAfterCursor( cursor , inclusive ) + { + var range = new CKEDITOR.dom.range(); + range.setStart( cursor.textNode, + ( inclusive ? cursor.offset : cursor.offset + 1 ) ); + range.setEndAt( editor.document.getBody(), + CKEDITOR.POSITION_BEFORE_END ); + return range; + } + + // The document range before the character cursor. + function getRangeBeforeCursor( cursor ) + { + var range = new CKEDITOR.dom.range(); + range.setStartAt( editor.document.getBody(), + CKEDITOR.POSITION_AFTER_START ); + range.setEnd( cursor.textNode, cursor.offset ); + return range; + } + + var KMP_NOMATCH = 0, + KMP_ADVANCED = 1, + KMP_MATCHED = 2; + /** + * Examination the occurrence of a word which implement KMP algorithm. + */ + var kmpMatcher = function( pattern, ignoreCase ) + { + var overlap = [ -1 ]; + if ( ignoreCase ) + pattern = pattern.toLowerCase(); + for ( var i = 0 ; i < pattern.length ; i++ ) + { + overlap.push( overlap[i] + 1 ); + while ( overlap[ i + 1 ] > 0 + && pattern.charAt( i ) != pattern + .charAt( overlap[ i + 1 ] - 1 ) ) + overlap[ i + 1 ] = overlap[ overlap[ i + 1 ] - 1 ] + 1; + } + + this._ = { + overlap : overlap, + state : 0, + ignoreCase : !!ignoreCase, + pattern : pattern + }; + }; + + kmpMatcher.prototype = + { + feedCharacter : function( c ) + { + if ( this._.ignoreCase ) + c = c.toLowerCase(); + + while ( true ) + { + if ( c == this._.pattern.charAt( this._.state ) ) + { + this._.state++; + if ( this._.state == this._.pattern.length ) + { + this._.state = 0; + return KMP_MATCHED; + } + return KMP_ADVANCED; + } + else if ( !this._.state ) + return KMP_NOMATCH; + else + this._.state = this._.overlap[ this._.state ]; + } + + return null; + }, + + reset : function() + { + this._.state = 0; + } + }; + + var wordSeparatorRegex = + /[.,"'?!;: \u0085\u00a0\u1680\u280e\u2028\u2029\u202f\u205f\u3000]/; + + var isWordSeparator = function( c ) + { + if ( !c ) + return true; + var code = c.charCodeAt( 0 ); + return ( code >= 9 && code <= 0xd ) + || ( code >= 0x2000 && code <= 0x200a ) + || wordSeparatorRegex.test( c ); + }; + + var finder = { + searchRange : null, + matchRange : null, + find : function( pattern, matchCase, matchWord, matchCyclic, highlightMatched, cyclicRerun ) + { + if ( !this.matchRange ) + this.matchRange = + new characterRange( + new characterWalker( this.searchRange ), + pattern.length ); + else + { + this.matchRange.removeHighlight(); + this.matchRange = this.matchRange.getNextCharacterRange( pattern.length ); + } + + var matcher = new kmpMatcher( pattern, !matchCase ), + matchState = KMP_NOMATCH, + character = '%'; + + while ( character !== null ) + { + this.matchRange.moveNext(); + while ( ( character = this.matchRange.getEndCharacter() ) ) + { + matchState = matcher.feedCharacter( character ); + if ( matchState == KMP_MATCHED ) + break; + if ( this.matchRange.moveNext().hitMatchBoundary ) + matcher.reset(); + } + + if ( matchState == KMP_MATCHED ) + { + if ( matchWord ) + { + var cursors = this.matchRange.getCursors(), + tail = cursors[ cursors.length - 1 ], + head = cursors[ 0 ]; + + var headWalker = new characterWalker( getRangeBeforeCursor( head ), true ), + tailWalker = new characterWalker( getRangeAfterCursor( tail ), true ); + + if ( ! ( isWordSeparator( headWalker.back().character ) + && isWordSeparator( tailWalker.next().character ) ) ) + continue; + } + this.matchRange.setMatched(); + if ( highlightMatched !== false ) + this.matchRange.highlight(); + return true; + } + } + + this.matchRange.clearMatched(); + this.matchRange.removeHighlight(); + // Clear current session and restart with the default search + // range. + // Re-run the finding once for cyclic.(#3517) + if ( matchCyclic && !cyclicRerun ) + { + this.searchRange = getSearchRange( 1 ); + this.matchRange = null; + return arguments.callee.apply( this, + Array.prototype.slice.call( arguments ).concat( [ true ] ) ); + } + + return false; + }, + + /** + * Record how much replacement occurred toward one replacing. + */ + replaceCounter : 0, + + replace : function( dialog, pattern, newString, matchCase, matchWord, + matchCyclic , isReplaceAll ) + { + isReplace = 1; + + // Successiveness of current replace/find. + var result = 0; + + // 1. Perform the replace when there's already a match here. + // 2. Otherwise perform the find but don't replace it immediately. + if ( this.matchRange && this.matchRange.isMatched() + && !this.matchRange._.isReplaced && !this.matchRange.isReadOnly() ) + { + // Turn off highlight for a while when saving snapshots. + this.matchRange.removeHighlight(); + var domRange = this.matchRange.toDomRange(); + var text = editor.document.createText( newString ); + if ( !isReplaceAll ) + { + // Save undo snaps before and after the replacement. + var selection = editor.getSelection(); + selection.selectRanges( [ domRange ] ); + editor.fire( 'saveSnapshot' ); + } + domRange.deleteContents(); + domRange.insertNode( text ); + if ( !isReplaceAll ) + { + selection.selectRanges( [ domRange ] ); + editor.fire( 'saveSnapshot' ); + } + this.matchRange.updateFromDomRange( domRange ); + if ( !isReplaceAll ) + this.matchRange.highlight(); + this.matchRange._.isReplaced = true; + this.replaceCounter++; + result = 1; + } + else + result = this.find( pattern, matchCase, matchWord, matchCyclic, !isReplaceAll ); + + isReplace = 0; + + return result; + } + }; + + /** + * The range in which find/replace happened, receive from user + * selection prior. + */ + function getSearchRange( isDefault ) + { + var searchRange, + sel = editor.getSelection(), + body = editor.document.getBody(); + if ( sel && !isDefault ) + { + searchRange = sel.getRanges()[ 0 ].clone(); + searchRange.collapse( true ); + } + else + { + searchRange = new CKEDITOR.dom.range(); + searchRange.setStartAt( body, CKEDITOR.POSITION_AFTER_START ); + } + searchRange.setEndAt( body, CKEDITOR.POSITION_BEFORE_END ); + return searchRange; + } + + var lang = editor.lang.findAndReplace; + return { + title : lang.title, + resizable : CKEDITOR.DIALOG_RESIZE_NONE, + minWidth : 350, + minHeight : 170, + buttons : [ CKEDITOR.dialog.cancelButton ], // Cancel button only. + contents : [ + { + id : 'find', + label : lang.find, + title : lang.find, + accessKey : '', + elements : [ + { + type : 'hbox', + widths : [ '230px', '90px' ], + children : + [ + { + type : 'text', + id : 'txtFindFind', + label : lang.findWhat, + isChanged : false, + labelLayout : 'horizontal', + accessKey : 'F' + }, + { + type : 'button', + id : 'btnFind', + align : 'left', + style : 'width:100%', + label : lang.find, + onClick : function() + { + var dialog = this.getDialog(); + if ( !finder.find( dialog.getValueOf( 'find', 'txtFindFind' ), + dialog.getValueOf( 'find', 'txtFindCaseChk' ), + dialog.getValueOf( 'find', 'txtFindWordChk' ), + dialog.getValueOf( 'find', 'txtFindCyclic' ) ) ) + alert( lang + .notFoundMsg ); + } + } + ] + }, + { + type : 'fieldset', + label : CKEDITOR.tools.htmlEncode( lang.findOptions ), + style : 'margin-top:29px', + children : + [ + { + type : 'vbox', + padding : 0, + children : + [ + { + type : 'checkbox', + id : 'txtFindCaseChk', + isChanged : false, + label : lang.matchCase + }, + { + type : 'checkbox', + id : 'txtFindWordChk', + isChanged : false, + label : lang.matchWord + }, + { + type : 'checkbox', + id : 'txtFindCyclic', + isChanged : false, + 'default' : true, + label : lang.matchCyclic + } + ] + } + ] + } + ] + }, + { + id : 'replace', + label : lang.replace, + accessKey : 'M', + elements : [ + { + type : 'hbox', + widths : [ '230px', '90px' ], + children : + [ + { + type : 'text', + id : 'txtFindReplace', + label : lang.findWhat, + isChanged : false, + labelLayout : 'horizontal', + accessKey : 'F' + }, + { + type : 'button', + id : 'btnFindReplace', + align : 'left', + style : 'width:100%', + label : lang.replace, + onClick : function() + { + var dialog = this.getDialog(); + if ( !finder.replace( dialog, + dialog.getValueOf( 'replace', 'txtFindReplace' ), + dialog.getValueOf( 'replace', 'txtReplace' ), + dialog.getValueOf( 'replace', 'txtReplaceCaseChk' ), + dialog.getValueOf( 'replace', 'txtReplaceWordChk' ), + dialog.getValueOf( 'replace', 'txtReplaceCyclic' ) ) ) + alert( lang + .notFoundMsg ); + } + } + ] + }, + { + type : 'hbox', + widths : [ '230px', '90px' ], + children : + [ + { + type : 'text', + id : 'txtReplace', + label : lang.replaceWith, + isChanged : false, + labelLayout : 'horizontal', + accessKey : 'R' + }, + { + type : 'button', + id : 'btnReplaceAll', + align : 'left', + style : 'width:100%', + label : lang.replaceAll, + isChanged : false, + onClick : function() + { + var dialog = this.getDialog(); + var replaceNums; + + finder.replaceCounter = 0; + + // Scope to full document. + finder.searchRange = getSearchRange( 1 ); + if ( finder.matchRange ) + { + finder.matchRange.removeHighlight(); + finder.matchRange = null; + } + editor.fire( 'saveSnapshot' ); + while ( finder.replace( dialog, + dialog.getValueOf( 'replace', 'txtFindReplace' ), + dialog.getValueOf( 'replace', 'txtReplace' ), + dialog.getValueOf( 'replace', 'txtReplaceCaseChk' ), + dialog.getValueOf( 'replace', 'txtReplaceWordChk' ), + false, true ) ) + { /*jsl:pass*/ } + + if ( finder.replaceCounter ) + { + alert( lang.replaceSuccessMsg.replace( /%1/, finder.replaceCounter ) ); + editor.fire( 'saveSnapshot' ); + } + else + alert( lang.notFoundMsg ); + } + } + ] + }, + { + type : 'fieldset', + label : CKEDITOR.tools.htmlEncode( lang.findOptions ), + children : + [ + { + type : 'vbox', + padding : 0, + children : + [ + { + type : 'checkbox', + id : 'txtReplaceCaseChk', + isChanged : false, + label : lang.matchCase + }, + { + type : 'checkbox', + id : 'txtReplaceWordChk', + isChanged : false, + label : lang.matchWord + }, + { + type : 'checkbox', + id : 'txtReplaceCyclic', + isChanged : false, + 'default' : true, + label : lang.matchCyclic + } + ] + } + ] + } + ] + } + ], + onLoad : function() + { + var dialog = this; + + // Keep track of the current pattern field in use. + var patternField, wholeWordChkField; + + // Ignore initial page select on dialog show + var isUserSelect = 0; + this.on( 'hide', function() + { + isUserSelect = 0; + }); + this.on( 'show', function() + { + isUserSelect = 1; + }); + + this.selectPage = CKEDITOR.tools.override( this.selectPage, function( originalFunc ) + { + return function( pageId ) + { + originalFunc.call( dialog, pageId ); + + var currPage = dialog._.tabs[ pageId ]; + var patternFieldInput, patternFieldId, wholeWordChkFieldId; + patternFieldId = pageId === 'find' ? 'txtFindFind' : 'txtFindReplace'; + wholeWordChkFieldId = pageId === 'find' ? 'txtFindWordChk' : 'txtReplaceWordChk'; + + patternField = dialog.getContentElement( pageId, + patternFieldId ); + wholeWordChkField = dialog.getContentElement( pageId, + wholeWordChkFieldId ); + + // Prepare for check pattern text filed 'keyup' event + if ( !currPage.initialized ) + { + patternFieldInput = CKEDITOR.document + .getById( patternField._.inputId ); + currPage.initialized = true; + } + + // Synchronize fields on tab switch. + if ( isUserSelect ) + syncFieldsBetweenTabs.call( this, pageId ); + }; + } ); + + }, + onShow : function() + { + // Establish initial searching start position. + finder.searchRange = getSearchRange(); + + // Fill in the find field with selected text. + var selectedText = this.getParentEditor().getSelection().getSelectedText(), + patternFieldId = ( startupPage == 'find' ? 'txtFindFind' : 'txtFindReplace' ); + + var field = this.getContentElement( startupPage, patternFieldId ); + field.setValue( selectedText ); + field.select(); + + this.selectPage( startupPage ); + + this[ ( startupPage == 'find' && this._.editor.readOnly? 'hide' : 'show' ) + 'Page' ]( 'replace'); + }, + onHide : function() + { + var range; + if ( finder.matchRange && finder.matchRange.isMatched() ) + { + finder.matchRange.removeHighlight(); + editor.focus(); + + range = finder.matchRange.toDomRange(); + if ( range ) + editor.getSelection().selectRanges( [ range ] ); + } + + // Clear current session before dialog close + delete finder.matchRange; + }, + onFocus : function() + { + if ( startupPage == 'replace' ) + return this.getContentElement( 'replace', 'txtFindReplace' ); + else + return this.getContentElement( 'find', 'txtFindFind' ); + } + }; + }; + + CKEDITOR.dialog.add( 'find', function( editor ) + { + return findDialog( editor, 'find' ); + }); + + CKEDITOR.dialog.add( 'replace', function( editor ) + { + return findDialog( editor, 'replace' ); + }); +})(); Index: 3rdParty_sources/ckeditor/plugins/flash/plugin.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/plugins/flash/plugin.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/plugins/flash/plugin.js 17 Aug 2012 14:15:52 -0000 1.1 @@ -0,0 +1,154 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +(function() +{ + var flashFilenameRegex = /\.swf(?:$|\?)/i; + + function isFlashEmbed( element ) + { + var attributes = element.attributes; + + return ( attributes.type == 'application/x-shockwave-flash' || flashFilenameRegex.test( attributes.src || '' ) ); + } + + function createFakeElement( editor, realElement ) + { + return editor.createFakeParserElement( realElement, 'cke_flash', 'flash', true ); + } + + CKEDITOR.plugins.add( 'flash', + { + init : function( editor ) + { + editor.addCommand( 'flash', new CKEDITOR.dialogCommand( 'flash' ) ); + editor.ui.addButton( 'Flash', + { + label : editor.lang.common.flash, + command : 'flash' + }); + CKEDITOR.dialog.add( 'flash', this.path + 'dialogs/flash.js' ); + + editor.addCss( + 'img.cke_flash' + + '{' + + 'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/placeholder.png' ) + ');' + + 'background-position: center center;' + + 'background-repeat: no-repeat;' + + 'border: 1px solid #a9a9a9;' + + 'width: 80px;' + + 'height: 80px;' + + '}' + ); + + // If the "menu" plugin is loaded, register the menu items. + if ( editor.addMenuItems ) + { + editor.addMenuItems( + { + flash : + { + label : editor.lang.flash.properties, + command : 'flash', + group : 'flash' + } + }); + } + + editor.on( 'doubleclick', function( evt ) + { + var element = evt.data.element; + + if ( element.is( 'img' ) && element.data( 'cke-real-element-type' ) == 'flash' ) + evt.data.dialog = 'flash'; + }); + + // If the "contextmenu" plugin is loaded, register the listeners. + if ( editor.contextMenu ) + { + editor.contextMenu.addListener( function( element, selection ) + { + if ( element && element.is( 'img' ) && !element.isReadOnly() + && element.data( 'cke-real-element-type' ) == 'flash' ) + return { flash : CKEDITOR.TRISTATE_OFF }; + }); + } + }, + + afterInit : function( editor ) + { + var dataProcessor = editor.dataProcessor, + dataFilter = dataProcessor && dataProcessor.dataFilter; + + if ( dataFilter ) + { + dataFilter.addRules( + { + elements : + { + 'cke:object' : function( element ) + { + var attributes = element.attributes, + classId = attributes.classid && String( attributes.classid ).toLowerCase(); + + if ( !classId && !isFlashEmbed( element ) ) + { + // Look for the inner + for ( var i = 0 ; i < element.children.length ; i++ ) + { + if ( element.children[ i ].name == 'cke:embed' ) + { + if ( !isFlashEmbed( element.children[ i ] ) ) + return null; + + return createFakeElement( editor, element ); + } + } + return null; + } + + return createFakeElement( editor, element ); + }, + + 'cke:embed' : function( element ) + { + if ( !isFlashEmbed( element ) ) + return null; + + return createFakeElement( editor, element ); + } + } + }, + 5); + } + }, + + requires : [ 'fakeobjects' ] + }); +})(); + +CKEDITOR.tools.extend( CKEDITOR.config, +{ + /** + * Save as EMBED tag only. This tag is unrecommended. + * @type Boolean + * @default false + */ + flashEmbedTagOnly : false, + + /** + * Add EMBED tag as alternative: <object><embed></embed></object> + * @type Boolean + * @default false + */ + flashAddEmbedTag : true, + + /** + * Use embedTagOnly and addEmbedTag values on edit. + * @type Boolean + * @default false + */ + flashConvertOnEdit : false +} ); Index: 3rdParty_sources/ckeditor/plugins/flash/dialogs/flash.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/plugins/flash/dialogs/flash.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/plugins/flash/dialogs/flash.js 17 Aug 2012 14:15:52 -0000 1.1 @@ -0,0 +1,674 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +(function() +{ + /* + * It is possible to set things in three different places. + * 1. As attributes in the object tag. + * 2. As param tags under the object tag. + * 3. As attributes in the embed tag. + * It is possible for a single attribute to be present in more than one place. + * So let's define a mapping between a sementic attribute and its syntactic + * equivalents. + * Then we'll set and retrieve attribute values according to the mapping, + * instead of having to check and set each syntactic attribute every time. + * + * Reference: http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_12701 + */ + var ATTRTYPE_OBJECT = 1, + ATTRTYPE_PARAM = 2, + ATTRTYPE_EMBED = 4; + + var attributesMap = + { + id : [ { type : ATTRTYPE_OBJECT, name : 'id' } ], + classid : [ { type : ATTRTYPE_OBJECT, name : 'classid' } ], + codebase : [ { type : ATTRTYPE_OBJECT, name : 'codebase'} ], + pluginspage : [ { type : ATTRTYPE_EMBED, name : 'pluginspage' } ], + src : [ { type : ATTRTYPE_PARAM, name : 'movie' }, { type : ATTRTYPE_EMBED, name : 'src' }, { type : ATTRTYPE_OBJECT, name : 'data' } ], + name : [ { type : ATTRTYPE_EMBED, name : 'name' } ], + align : [ { type : ATTRTYPE_OBJECT, name : 'align' } ], + title : [ { type : ATTRTYPE_OBJECT, name : 'title' }, { type : ATTRTYPE_EMBED, name : 'title' } ], + 'class' : [ { type : ATTRTYPE_OBJECT, name : 'class' }, { type : ATTRTYPE_EMBED, name : 'class'} ], + width : [ { type : ATTRTYPE_OBJECT, name : 'width' }, { type : ATTRTYPE_EMBED, name : 'width' } ], + height : [ { type : ATTRTYPE_OBJECT, name : 'height' }, { type : ATTRTYPE_EMBED, name : 'height' } ], + hSpace : [ { type : ATTRTYPE_OBJECT, name : 'hSpace' }, { type : ATTRTYPE_EMBED, name : 'hSpace' } ], + vSpace : [ { type : ATTRTYPE_OBJECT, name : 'vSpace' }, { type : ATTRTYPE_EMBED, name : 'vSpace' } ], + style : [ { type : ATTRTYPE_OBJECT, name : 'style' }, { type : ATTRTYPE_EMBED, name : 'style' } ], + type : [ { type : ATTRTYPE_EMBED, name : 'type' } ] + }; + + var names = [ 'play', 'loop', 'menu', 'quality', 'scale', 'salign', 'wmode', 'bgcolor', 'base', 'flashvars', 'allowScriptAccess', + 'allowFullScreen' ]; + for ( var i = 0 ; i < names.length ; i++ ) + attributesMap[ names[i] ] = [ { type : ATTRTYPE_EMBED, name : names[i] }, { type : ATTRTYPE_PARAM, name : names[i] } ]; + names = [ 'allowFullScreen', 'play', 'loop', 'menu' ]; + for ( i = 0 ; i < names.length ; i++ ) + attributesMap[ names[i] ][0]['default'] = attributesMap[ names[i] ][1]['default'] = true; + + var defaultToPixel = CKEDITOR.tools.cssLength; + + function loadValue( objectNode, embedNode, paramMap ) + { + var attributes = attributesMap[ this.id ]; + if ( !attributes ) + return; + + var isCheckbox = ( this instanceof CKEDITOR.ui.dialog.checkbox ); + for ( var i = 0 ; i < attributes.length ; i++ ) + { + var attrDef = attributes[ i ]; + switch ( attrDef.type ) + { + case ATTRTYPE_OBJECT: + if ( !objectNode ) + continue; + if ( objectNode.getAttribute( attrDef.name ) !== null ) + { + var value = objectNode.getAttribute( attrDef.name ); + if ( isCheckbox ) + this.setValue( value.toLowerCase() == 'true' ); + else + this.setValue( value ); + return; + } + else if ( isCheckbox ) + this.setValue( !!attrDef[ 'default' ] ); + break; + case ATTRTYPE_PARAM: + if ( !objectNode ) + continue; + if ( attrDef.name in paramMap ) + { + value = paramMap[ attrDef.name ]; + if ( isCheckbox ) + this.setValue( value.toLowerCase() == 'true' ); + else + this.setValue( value ); + return; + } + else if ( isCheckbox ) + this.setValue( !!attrDef[ 'default' ] ); + break; + case ATTRTYPE_EMBED: + if ( !embedNode ) + continue; + if ( embedNode.getAttribute( attrDef.name ) ) + { + value = embedNode.getAttribute( attrDef.name ); + if ( isCheckbox ) + this.setValue( value.toLowerCase() == 'true' ); + else + this.setValue( value ); + return; + } + else if ( isCheckbox ) + this.setValue( !!attrDef[ 'default' ] ); + } + } + } + + function commitValue( objectNode, embedNode, paramMap ) + { + var attributes = attributesMap[ this.id ]; + if ( !attributes ) + return; + + var isRemove = ( this.getValue() === '' ), + isCheckbox = ( this instanceof CKEDITOR.ui.dialog.checkbox ); + + for ( var i = 0 ; i < attributes.length ; i++ ) + { + var attrDef = attributes[i]; + switch ( attrDef.type ) + { + case ATTRTYPE_OBJECT: + // Avoid applying the data attribute when not needed (#7733) + if ( !objectNode || ( attrDef.name == 'data' && embedNode && !objectNode.hasAttribute( 'data' ) ) ) + continue; + var value = this.getValue(); + if ( isRemove || isCheckbox && value === attrDef[ 'default' ] ) + objectNode.removeAttribute( attrDef.name ); + else + objectNode.setAttribute( attrDef.name, value ); + break; + case ATTRTYPE_PARAM: + if ( !objectNode ) + continue; + value = this.getValue(); + if ( isRemove || isCheckbox && value === attrDef[ 'default' ] ) + { + if ( attrDef.name in paramMap ) + paramMap[ attrDef.name ].remove(); + } + else + { + if ( attrDef.name in paramMap ) + paramMap[ attrDef.name ].setAttribute( 'value', value ); + else + { + var param = CKEDITOR.dom.element.createFromHtml( '', objectNode.getDocument() ); + param.setAttributes( { name : attrDef.name, value : value } ); + if ( objectNode.getChildCount() < 1 ) + param.appendTo( objectNode ); + else + param.insertBefore( objectNode.getFirst() ); + } + } + break; + case ATTRTYPE_EMBED: + if ( !embedNode ) + continue; + value = this.getValue(); + if ( isRemove || isCheckbox && value === attrDef[ 'default' ]) + embedNode.removeAttribute( attrDef.name ); + else + embedNode.setAttribute( attrDef.name, value ); + } + } + } + + CKEDITOR.dialog.add( 'flash', function( editor ) + { + var makeObjectTag = !editor.config.flashEmbedTagOnly, + makeEmbedTag = editor.config.flashAddEmbedTag || editor.config.flashEmbedTagOnly; + + var previewPreloader, + previewAreaHtml = '
      ' + CKEDITOR.tools.htmlEncode( editor.lang.common.preview ) +'
      ' + + '' + + '
      '; + + return { + title : editor.lang.flash.title, + minWidth : 420, + minHeight : 310, + onShow : function() + { + // Clear previously saved elements. + this.fakeImage = this.objectNode = this.embedNode = null; + previewPreloader = new CKEDITOR.dom.element( 'embed', editor.document ); + + // Try to detect any embed or object tag that has Flash parameters. + var fakeImage = this.getSelectedElement(); + if ( fakeImage && fakeImage.data( 'cke-real-element-type' ) && fakeImage.data( 'cke-real-element-type' ) == 'flash' ) + { + this.fakeImage = fakeImage; + + var realElement = editor.restoreRealElement( fakeImage ), + objectNode = null, embedNode = null, paramMap = {}; + if ( realElement.getName() == 'cke:object' ) + { + objectNode = realElement; + var embedList = objectNode.getElementsByTag( 'embed', 'cke' ); + if ( embedList.count() > 0 ) + embedNode = embedList.getItem( 0 ); + var paramList = objectNode.getElementsByTag( 'param', 'cke' ); + for ( var i = 0, length = paramList.count() ; i < length ; i++ ) + { + var item = paramList.getItem( i ), + name = item.getAttribute( 'name' ), + value = item.getAttribute( 'value' ); + paramMap[ name ] = value; + } + } + else if ( realElement.getName() == 'cke:embed' ) + embedNode = realElement; + + this.objectNode = objectNode; + this.embedNode = embedNode; + + this.setupContent( objectNode, embedNode, paramMap, fakeImage ); + } + }, + onOk : function() + { + // If there's no selected object or embed, create one. Otherwise, reuse the + // selected object and embed nodes. + var objectNode = null, + embedNode = null, + paramMap = null; + if ( !this.fakeImage ) + { + if ( makeObjectTag ) + { + objectNode = CKEDITOR.dom.element.createFromHtml( '', editor.document ); + var attributes = { + classid : 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000', + codebase : 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0' + }; + objectNode.setAttributes( attributes ); + } + if ( makeEmbedTag ) + { + embedNode = CKEDITOR.dom.element.createFromHtml( '', editor.document ); + embedNode.setAttributes( + { + type : 'application/x-shockwave-flash', + pluginspage : 'http://www.macromedia.com/go/getflashplayer' + } ); + if ( objectNode ) + embedNode.appendTo( objectNode ); + } + } + else + { + objectNode = this.objectNode; + embedNode = this.embedNode; + } + + // Produce the paramMap if there's an object tag. + if ( objectNode ) + { + paramMap = {}; + var paramList = objectNode.getElementsByTag( 'param', 'cke' ); + for ( var i = 0, length = paramList.count() ; i < length ; i++ ) + paramMap[ paramList.getItem( i ).getAttribute( 'name' ) ] = paramList.getItem( i ); + } + + // A subset of the specified attributes/styles + // should also be applied on the fake element to + // have better visual effect. (#5240) + var extraStyles = {}, extraAttributes = {}; + this.commitContent( objectNode, embedNode, paramMap, extraStyles, extraAttributes ); + + // Refresh the fake image. + var newFakeImage = editor.createFakeElement( objectNode || embedNode, 'cke_flash', 'flash', true ); + newFakeImage.setAttributes( extraAttributes ); + newFakeImage.setStyles( extraStyles ); + if ( this.fakeImage ) + { + newFakeImage.replace( this.fakeImage ); + editor.getSelection().selectElement( newFakeImage ); + } + else + editor.insertElement( newFakeImage ); + }, + + onHide : function() + { + if ( this.preview ) + this.preview.setHtml(''); + }, + + contents : [ + { + id : 'info', + label : editor.lang.common.generalTab, + accessKey : 'I', + elements : + [ + { + type : 'vbox', + padding : 0, + children : + [ + { + type : 'hbox', + widths : [ '280px', '110px' ], + align : 'right', + children : + [ + { + id : 'src', + type : 'text', + label : editor.lang.common.url, + required : true, + validate : CKEDITOR.dialog.validate.notEmpty( editor.lang.flash.validateSrc ), + setup : loadValue, + commit : commitValue, + onLoad : function() + { + var dialog = this.getDialog(), + updatePreview = function( src ){ + // Query the preloader to figure out the url impacted by based href. + previewPreloader.setAttribute( 'src', src ); + dialog.preview.setHtml( '' ); + }; + // Preview element + dialog.preview = dialog.getContentElement( 'info', 'preview' ).getElement().getChild( 3 ); + + // Sync on inital value loaded. + this.on( 'change', function( evt ){ + + if ( evt.data && evt.data.value ) + updatePreview( evt.data.value ); + } ); + // Sync when input value changed. + this.getInputElement().on( 'change', function( evt ){ + + updatePreview( this.getValue() ); + }, this ); + } + }, + { + type : 'button', + id : 'browse', + filebrowser : 'info:src', + hidden : true, + // v-align with the 'src' field. + // TODO: We need something better than a fixed size here. + style : 'display:inline-block;margin-top:10px;', + label : editor.lang.common.browseServer + } + ] + } + ] + }, + { + type : 'hbox', + widths : [ '25%', '25%', '25%', '25%', '25%' ], + children : + [ + { + type : 'text', + id : 'width', + style : 'width:95px', + label : editor.lang.common.width, + validate : CKEDITOR.dialog.validate.htmlLength( editor.lang.common.invalidHtmlLength.replace( '%1', editor.lang.common.width ) ), + setup : loadValue, + commit : commitValue + }, + { + type : 'text', + id : 'height', + style : 'width:95px', + label : editor.lang.common.height, + validate : CKEDITOR.dialog.validate.htmlLength( editor.lang.common.invalidHtmlLength.replace( '%1', editor.lang.common.height ) ), + setup : loadValue, + commit : commitValue + }, + { + type : 'text', + id : 'hSpace', + style : 'width:95px', + label : editor.lang.flash.hSpace, + validate : CKEDITOR.dialog.validate.integer( editor.lang.flash.validateHSpace ), + setup : loadValue, + commit : commitValue + }, + { + type : 'text', + id : 'vSpace', + style : 'width:95px', + label : editor.lang.flash.vSpace, + validate : CKEDITOR.dialog.validate.integer( editor.lang.flash.validateVSpace ), + setup : loadValue, + commit : commitValue + } + ] + }, + + { + type : 'vbox', + children : + [ + { + type : 'html', + id : 'preview', + style : 'width:95%;', + html : previewAreaHtml + } + ] + } + ] + }, + { + id : 'Upload', + hidden : true, + filebrowser : 'uploadButton', + label : editor.lang.common.upload, + elements : + [ + { + type : 'file', + id : 'upload', + label : editor.lang.common.upload, + size : 38 + }, + { + type : 'fileButton', + id : 'uploadButton', + label : editor.lang.common.uploadSubmit, + filebrowser : 'info:src', + 'for' : [ 'Upload', 'upload' ] + } + ] + }, + { + id : 'properties', + label : editor.lang.flash.propertiesTab, + elements : + [ + { + type : 'hbox', + widths : [ '50%', '50%' ], + children : + [ + { + id : 'scale', + type : 'select', + label : editor.lang.flash.scale, + 'default' : '', + style : 'width : 100%;', + items : + [ + [ editor.lang.common.notSet , ''], + [ editor.lang.flash.scaleAll, 'showall' ], + [ editor.lang.flash.scaleNoBorder, 'noborder' ], + [ editor.lang.flash.scaleFit, 'exactfit' ] + ], + setup : loadValue, + commit : commitValue + }, + { + id : 'allowScriptAccess', + type : 'select', + label : editor.lang.flash.access, + 'default' : '', + style : 'width : 100%;', + items : + [ + [ editor.lang.common.notSet , ''], + [ editor.lang.flash.accessAlways, 'always' ], + [ editor.lang.flash.accessSameDomain, 'samedomain' ], + [ editor.lang.flash.accessNever, 'never' ] + ], + setup : loadValue, + commit : commitValue + } + ] + }, + { + type : 'hbox', + widths : [ '50%', '50%' ], + children : + [ + { + id : 'wmode', + type : 'select', + label : editor.lang.flash.windowMode, + 'default' : '', + style : 'width : 100%;', + items : + [ + [ editor.lang.common.notSet , '' ], + [ editor.lang.flash.windowModeWindow, 'window' ], + [ editor.lang.flash.windowModeOpaque, 'opaque' ], + [ editor.lang.flash.windowModeTransparent, 'transparent' ] + ], + setup : loadValue, + commit : commitValue + }, + { + id : 'quality', + type : 'select', + label : editor.lang.flash.quality, + 'default' : 'high', + style : 'width : 100%;', + items : + [ + [ editor.lang.common.notSet , '' ], + [ editor.lang.flash.qualityBest, 'best' ], + [ editor.lang.flash.qualityHigh, 'high' ], + [ editor.lang.flash.qualityAutoHigh, 'autohigh' ], + [ editor.lang.flash.qualityMedium, 'medium' ], + [ editor.lang.flash.qualityAutoLow, 'autolow' ], + [ editor.lang.flash.qualityLow, 'low' ] + ], + setup : loadValue, + commit : commitValue + } + ] + }, + { + type : 'hbox', + widths : [ '50%', '50%' ], + children : + [ + { + id : 'align', + type : 'select', + label : editor.lang.common.align, + 'default' : '', + style : 'width : 100%;', + items : + [ + [ editor.lang.common.notSet , ''], + [ editor.lang.common.alignLeft , 'left'], + [ editor.lang.flash.alignAbsBottom , 'absBottom'], + [ editor.lang.flash.alignAbsMiddle , 'absMiddle'], + [ editor.lang.flash.alignBaseline , 'baseline'], + [ editor.lang.common.alignBottom , 'bottom'], + [ editor.lang.common.alignMiddle , 'middle'], + [ editor.lang.common.alignRight , 'right'], + [ editor.lang.flash.alignTextTop , 'textTop'], + [ editor.lang.common.alignTop , 'top'] + ], + setup : loadValue, + commit : function( objectNode, embedNode, paramMap, extraStyles, extraAttributes ) + { + var value = this.getValue(); + commitValue.apply( this, arguments ); + value && ( extraAttributes.align = value ); + } + }, + { + type : 'html', + html : '
      ' + } + ] + }, + { + type : 'fieldset', + label : CKEDITOR.tools.htmlEncode( editor.lang.flash.flashvars ), + children : + [ + { + type : 'vbox', + padding : 0, + children : + [ + { + type : 'checkbox', + id : 'menu', + label : editor.lang.flash.chkMenu, + 'default' : true, + setup : loadValue, + commit : commitValue + }, + { + type : 'checkbox', + id : 'play', + label : editor.lang.flash.chkPlay, + 'default' : true, + setup : loadValue, + commit : commitValue + }, + { + type : 'checkbox', + id : 'loop', + label : editor.lang.flash.chkLoop, + 'default' : true, + setup : loadValue, + commit : commitValue + }, + { + type : 'checkbox', + id : 'allowFullScreen', + label : editor.lang.flash.chkFull, + 'default' : true, + setup : loadValue, + commit : commitValue + } + ] + } + ] + } + ] + }, + { + id : 'advanced', + label : editor.lang.common.advancedTab, + elements : + [ + { + type : 'hbox', + widths : [ '45%', '55%' ], + children : + [ + { + type : 'text', + id : 'id', + label : editor.lang.common.id, + setup : loadValue, + commit : commitValue + }, + { + type : 'text', + id : 'title', + label : editor.lang.common.advisoryTitle, + setup : loadValue, + commit : commitValue + } + ] + }, + { + type : 'hbox', + widths : [ '45%', '55%' ], + children : + [ + { + type : 'text', + id : 'bgcolor', + label : editor.lang.flash.bgcolor, + setup : loadValue, + commit : commitValue + }, + { + type : 'text', + id : 'class', + label : editor.lang.common.cssClass, + setup : loadValue, + commit : commitValue + } + ] + }, + { + type : 'text', + id : 'style', + validate : CKEDITOR.dialog.validate.inlineStyle( editor.lang.common.invalidInlineStyle ), + label : editor.lang.common.cssStyle, + setup : loadValue, + commit : commitValue + } + ] + } + ] + }; + } ); +})(); Index: 3rdParty_sources/ckeditor/plugins/flash/images/placeholder.png =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/plugins/flash/images/placeholder.png,v diff -u Binary files differ Index: 3rdParty_sources/ckeditor/plugins/floatpanel/plugin.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/plugins/floatpanel/plugin.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/plugins/floatpanel/plugin.js 17 Aug 2012 14:15:49 -0000 1.1 @@ -0,0 +1,428 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +CKEDITOR.plugins.add( 'floatpanel', +{ + requires : [ 'panel' ] +}); + +(function() +{ + var panels = {}; + var isShowing = false; + + function getPanel( editor, doc, parentElement, definition, level ) + { + // Generates the panel key: docId-eleId-skinName-langDir[-uiColor][-CSSs][-level] + var key = CKEDITOR.tools.genKey( doc.getUniqueId(), parentElement.getUniqueId(), editor.skinName, editor.lang.dir, + editor.uiColor || '', definition.css || '', level || '' ); + + var panel = panels[ key ]; + + if ( !panel ) + { + panel = panels[ key ] = new CKEDITOR.ui.panel( doc, definition ); + panel.element = parentElement.append( CKEDITOR.dom.element.createFromHtml( panel.renderHtml( editor ), doc ) ); + + panel.element.setStyles( + { + display : 'none', + position : 'absolute' + }); + } + + return panel; + } + + CKEDITOR.ui.floatPanel = CKEDITOR.tools.createClass( + { + $ : function( editor, parentElement, definition, level ) + { + definition.forceIFrame = 1; + + var doc = parentElement.getDocument(), + panel = getPanel( editor, doc, parentElement, definition, level || 0 ), + element = panel.element, + iframe = element.getFirst().getFirst(); + + this.element = element; + + this._ = + { + editor : editor, + // The panel that will be floating. + panel : panel, + parentElement : parentElement, + definition : definition, + document : doc, + iframe : iframe, + children : [], + dir : editor.lang.dir + }; + + editor.on( 'mode', function(){ this.hide(); }, this ); + }, + + proto : + { + addBlock : function( name, block ) + { + return this._.panel.addBlock( name, block ); + }, + + addListBlock : function( name, multiSelect ) + { + return this._.panel.addListBlock( name, multiSelect ); + }, + + getBlock : function( name ) + { + return this._.panel.getBlock( name ); + }, + + /* + corner (LTR): + 1 = top-left + 2 = top-right + 3 = bottom-right + 4 = bottom-left + + corner (RTL): + 1 = top-right + 2 = top-left + 3 = bottom-left + 4 = bottom-right + */ + showBlock : function( name, offsetParent, corner, offsetX, offsetY ) + { + var panel = this._.panel, + block = panel.showBlock( name ); + + this.allowBlur( false ); + isShowing = 1; + + // Record from where the focus is when open panel. + this._.returnFocus = this._.editor.focusManager.hasFocus ? this._.editor : new CKEDITOR.dom.element( CKEDITOR.document.$.activeElement ); + + + var element = this.element, + iframe = this._.iframe, + definition = this._.definition, + position = offsetParent.getDocumentPosition( element.getDocument() ), + rtl = this._.dir == 'rtl'; + + var left = position.x + ( offsetX || 0 ), + top = position.y + ( offsetY || 0 ); + + // Floating panels are off by (-1px, 0px) in RTL mode. (#3438) + if ( rtl && ( corner == 1 || corner == 4 ) ) + left += offsetParent.$.offsetWidth; + else if ( !rtl && ( corner == 2 || corner == 3 ) ) + left += offsetParent.$.offsetWidth - 1; + + if ( corner == 3 || corner == 4 ) + top += offsetParent.$.offsetHeight - 1; + + // Memorize offsetParent by it's ID. + this._.panel._.offsetParentId = offsetParent.getId(); + + element.setStyles( + { + top : top + 'px', + left: 0, + display : '' + }); + + // Don't use display or visibility style because we need to + // calculate the rendering layout later and focus the element. + element.setOpacity( 0 ); + + // To allow the context menu to decrease back their width + element.getFirst().removeStyle( 'width' ); + + // Configure the IFrame blur event. Do that only once. + if ( !this._.blurSet ) + { + // Non IE prefer the event into a window object. + var focused = CKEDITOR.env.ie ? iframe : new CKEDITOR.dom.window( iframe.$.contentWindow ); + + // With addEventListener compatible browsers, we must + // useCapture when registering the focus/blur events to + // guarantee they will be firing in all situations. (#3068, #3222 ) + CKEDITOR.event.useCapture = true; + + focused.on( 'blur', function( ev ) + { + if ( !this.allowBlur() ) + return; + + // As we are using capture to register the listener, + // the blur event may get fired even when focusing + // inside the window itself, so we must ensure the + // target is out of it. + var target = ev.data.getTarget() ; + if ( target.getName && target.getName() != 'iframe' ) + return; + + if ( this.visible && !this._.activeChild && !isShowing ) + { + // Panel close is caused by user's navigating away the focus, e.g. click outside the panel. + // DO NOT restore focus in this case. + delete this._.returnFocus; + this.hide(); + } + }, + this ); + + focused.on( 'focus', function() + { + this._.focused = true; + this.hideChild(); + this.allowBlur( true ); + }, + this ); + + CKEDITOR.event.useCapture = false; + + this._.blurSet = 1; + } + + panel.onEscape = CKEDITOR.tools.bind( function( keystroke ) + { + if ( this.onEscape && this.onEscape( keystroke ) === false ) + return false; + }, + this ); + + CKEDITOR.tools.setTimeout( function() + { + if ( rtl ) + left -= element.$.offsetWidth; + + var panelLoad = CKEDITOR.tools.bind( function () + { + var target = element.getFirst(); + + if ( block.autoSize ) + { + // We must adjust first the width or IE6 could include extra lines in the height computation + var widthNode = block.element.$; + + if ( CKEDITOR.env.gecko || CKEDITOR.env.opera ) + widthNode = widthNode.parentNode; + + if ( CKEDITOR.env.ie ) + widthNode = widthNode.document.body; + + var width = widthNode.scrollWidth; + // Account for extra height needed due to IE quirks box model bug: + // http://en.wikipedia.org/wiki/Internet_Explorer_box_model_bug + // (#3426) + if ( CKEDITOR.env.ie && CKEDITOR.env.quirks && width > 0 ) + width += ( target.$.offsetWidth || 0 ) - ( target.$.clientWidth || 0 ) + 3; + // A little extra at the end. + // If not present, IE6 might break into the next line, but also it looks better this way + width += 4 ; + + target.setStyle( 'width', width + 'px' ); + + // IE doesn't compute the scrollWidth if a filter is applied previously + block.element.addClass( 'cke_frameLoaded' ); + + var height = block.element.$.scrollHeight; + + // Account for extra height needed due to IE quirks box model bug: + // http://en.wikipedia.org/wiki/Internet_Explorer_box_model_bug + // (#3426) + if ( CKEDITOR.env.ie && CKEDITOR.env.quirks && height > 0 ) + height += ( target.$.offsetHeight || 0 ) - ( target.$.clientHeight || 0 ) + 3; + + target.setStyle( 'height', height + 'px' ); + + // Fix IE < 8 visibility. + panel._.currentBlock.element.setStyle( 'display', 'none' ).removeStyle( 'display' ); + } + else + target.removeStyle( 'height' ); + + var panelElement = panel.element, + panelWindow = panelElement.getWindow(), + windowScroll = panelWindow.getScrollPosition(), + viewportSize = panelWindow.getViewPaneSize(), + panelSize = + { + 'height' : panelElement.$.offsetHeight, + 'width' : panelElement.$.offsetWidth + }; + + // If the menu is horizontal off, shift it toward + // the opposite language direction. + if ( rtl ? left < 0 : left + panelSize.width > viewportSize.width + windowScroll.x ) + left += ( panelSize.width * ( rtl ? 1 : -1 ) ); + + // Vertical off screen is simpler. + if ( top + panelSize.height > viewportSize.height + windowScroll.y ) + top -= panelSize.height; + + // If IE is in RTL, we have troubles with absolute + // position and horizontal scrolls. Here we have a + // series of hacks to workaround it. (#6146) + if ( CKEDITOR.env.ie ) + { + var offsetParent = new CKEDITOR.dom.element( element.$.offsetParent ), + scrollParent = offsetParent; + + // Quirks returns , but standards returns . + if ( scrollParent.getName() == 'html' ) + scrollParent = scrollParent.getDocument().getBody(); + + if ( scrollParent.getComputedStyle( 'direction' ) == 'rtl' ) + { + // For IE8, there is not much logic on this, but it works. + if ( CKEDITOR.env.ie8Compat ) + left -= element.getDocument().getDocumentElement().$.scrollLeft * 2; + else + left -= ( offsetParent.$.scrollWidth - offsetParent.$.clientWidth ); + } + } + + // Trigger the onHide event of the previously active panel to prevent + // incorrect styles from being applied (#6170) + var innerElement = element.getFirst(), + activePanel; + if ( ( activePanel = innerElement.getCustomData( 'activePanel' ) ) ) + activePanel.onHide && activePanel.onHide.call( this, 1 ); + innerElement.setCustomData( 'activePanel', this ); + + element.setStyles( + { + top : top + 'px', + left : left + 'px' + } ); + element.setOpacity( 1 ); + } , this ); + + panel.isLoaded ? panelLoad() : panel.onLoad = panelLoad; + + // Set the panel frame focus, so the blur event gets fired. + CKEDITOR.tools.setTimeout( function() + { + iframe.$.contentWindow.focus(); + // We need this get fired manually because of unfired focus() function. + this.allowBlur( true ); + }, 0, this); + }, CKEDITOR.env.air ? 200 : 0, this); + this.visible = 1; + + if ( this.onShow ) + this.onShow.call( this ); + + isShowing = 0; + }, + + hide : function( returnFocus ) + { + if ( this.visible && ( !this.onHide || this.onHide.call( this ) !== true ) ) + { + this.hideChild(); + // Blur previously focused element. (#6671) + CKEDITOR.env.gecko && this._.iframe.getFrameDocument().$.activeElement.blur(); + this.element.setStyle( 'display', 'none' ); + this.visible = 0; + this.element.getFirst().removeCustomData( 'activePanel' ); + + // Return focus properly. (#6247) + var focusReturn = returnFocus !== false && this._.returnFocus; + if ( focusReturn ) + { + // Webkit requires focus moved out panel iframe first. + if ( CKEDITOR.env.webkit && focusReturn.type ) + focusReturn.getWindow().$.focus(); + + focusReturn.focus(); + } + } + }, + + allowBlur : function( allow ) // Prevent editor from hiding the panel. #3222. + { + var panel = this._.panel; + if ( allow != undefined ) + panel.allowBlur = allow; + + return panel.allowBlur; + }, + + showAsChild : function( panel, blockName, offsetParent, corner, offsetX, offsetY ) + { + // Skip reshowing of child which is already visible. + if ( this._.activeChild == panel && panel._.panel._.offsetParentId == offsetParent.getId() ) + return; + + this.hideChild(); + + panel.onHide = CKEDITOR.tools.bind( function() + { + // Use a timeout, so we give time for this menu to get + // potentially focused. + CKEDITOR.tools.setTimeout( function() + { + if ( !this._.focused ) + this.hide(); + }, + 0, this ); + }, + this ); + + this._.activeChild = panel; + this._.focused = false; + + panel.showBlock( blockName, offsetParent, corner, offsetX, offsetY ); + + /* #3767 IE: Second level menu may not have borders */ + if ( CKEDITOR.env.ie7Compat || ( CKEDITOR.env.ie8 && CKEDITOR.env.ie6Compat ) ) + { + setTimeout(function() + { + panel.element.getChild( 0 ).$.style.cssText += ''; + }, 100); + } + }, + + hideChild : function() + { + var activeChild = this._.activeChild; + + if ( activeChild ) + { + delete activeChild.onHide; + // Sub panels don't manage focus. (#7881) + delete activeChild._.returnFocus; + delete this._.activeChild; + activeChild.hide(); + } + } + } + }); + + CKEDITOR.on( 'instanceDestroyed', function() + { + var isLastInstance = CKEDITOR.tools.isEmpty( CKEDITOR.instances ); + + for ( var i in panels ) + { + var panel = panels[ i ]; + // Safe to destroy it since there're no more instances.(#4241) + if ( isLastInstance ) + panel.destroy(); + // Panel might be used by other instances, just hide them.(#4552) + else + panel.element.hide(); + } + // Remove the registration. + isLastInstance && ( panels = {} ); + + } ); +})(); Index: 3rdParty_sources/ckeditor/plugins/font/plugin.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/plugins/font/plugin.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/plugins/font/plugin.js 17 Aug 2012 14:15:52 -0000 1.1 @@ -0,0 +1,234 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +(function() +{ + function addCombo( editor, comboName, styleType, lang, entries, defaultLabel, styleDefinition ) + { + var config = editor.config; + + // Gets the list of fonts from the settings. + var names = entries.split( ';' ), + values = []; + + // Create style objects for all fonts. + var styles = {}; + for ( var i = 0 ; i < names.length ; i++ ) + { + var parts = names[ i ]; + + if ( parts ) + { + parts = parts.split( '/' ); + + var vars = {}, + name = names[ i ] = parts[ 0 ]; + + vars[ styleType ] = values[ i ] = parts[ 1 ] || name; + + styles[ name ] = new CKEDITOR.style( styleDefinition, vars ); + styles[ name ]._.definition.name = name; + } + else + names.splice( i--, 1 ); + } + + editor.ui.addRichCombo( comboName, + { + label : lang.label, + title : lang.panelTitle, + className : 'cke_' + ( styleType == 'size' ? 'fontSize' : 'font' ), + panel : + { + css : editor.skin.editor.css.concat( config.contentsCss ), + multiSelect : false, + attributes : { 'aria-label' : lang.panelTitle } + }, + + init : function() + { + this.startGroup( lang.panelTitle ); + + for ( var i = 0 ; i < names.length ; i++ ) + { + var name = names[ i ]; + + // Add the tag entry to the panel list. + this.add( name, styles[ name ].buildPreview(), name ); + } + }, + + onClick : function( value ) + { + editor.focus(); + editor.fire( 'saveSnapshot' ); + + var style = styles[ value ]; + + if ( this.getValue() == value ) + style.remove( editor.document ); + else + style.apply( editor.document ); + + editor.fire( 'saveSnapshot' ); + }, + + onRender : function() + { + editor.on( 'selectionChange', function( ev ) + { + var currentValue = this.getValue(); + + var elementPath = ev.data.path, + elements = elementPath.elements; + + // For each element into the elements path. + for ( var i = 0, element ; i < elements.length ; i++ ) + { + element = elements[i]; + + // Check if the element is removable by any of + // the styles. + for ( var value in styles ) + { + if ( styles[ value ].checkElementRemovable( element, true ) ) + { + if ( value != currentValue ) + this.setValue( value ); + return; + } + } + } + + // If no styles match, just empty it. + this.setValue( '', defaultLabel ); + }, + this); + } + }); + } + + CKEDITOR.plugins.add( 'font', + { + requires : [ 'richcombo', 'styles' ], + + init : function( editor ) + { + var config = editor.config; + + addCombo( editor, 'Font', 'family', editor.lang.font, config.font_names, config.font_defaultLabel, config.font_style ); + addCombo( editor, 'FontSize', 'size', editor.lang.fontSize, config.fontSize_sizes, config.fontSize_defaultLabel, config.fontSize_style ); + } + }); +})(); + +/** + * The list of fonts names to be displayed in the Font combo in the toolbar. + * Entries are separated by semi-colons (;), while it's possible to have more + * than one font for each entry, in the HTML way (separated by comma). + * + * A display name may be optionally defined by prefixing the entries with the + * name and the slash character. For example, "Arial/Arial, Helvetica, sans-serif" + * will be displayed as "Arial" in the list, but will be outputted as + * "Arial, Helvetica, sans-serif". + * @type String + * @example + * config.font_names = + * 'Arial/Arial, Helvetica, sans-serif;' + + * 'Times New Roman/Times New Roman, Times, serif;' + + * 'Verdana'; + * @example + * config.font_names = 'Arial;Times New Roman;Verdana'; + */ +CKEDITOR.config.font_names = + 'Arial/Arial, Helvetica, sans-serif;' + + 'Comic Sans MS/Comic Sans MS, cursive;' + + 'Courier New/Courier New, Courier, monospace;' + + 'Georgia/Georgia, serif;' + + 'Lucida Sans Unicode/Lucida Sans Unicode, Lucida Grande, sans-serif;' + + 'Tahoma/Tahoma, Geneva, sans-serif;' + + 'Times New Roman/Times New Roman, Times, serif;' + + 'Trebuchet MS/Trebuchet MS, Helvetica, sans-serif;' + + 'Verdana/Verdana, Geneva, sans-serif'; + +/** + * The text to be displayed in the Font combo is none of the available values + * matches the current cursor position or text selection. + * @type String + * @example + * // If the default site font is Arial, we may making it more explicit to the end user. + * config.font_defaultLabel = 'Arial'; + */ +CKEDITOR.config.font_defaultLabel = ''; + +/** + * The style definition to be used to apply the font in the text. + * @type Object + * @example + * // This is actually the default value for it. + * config.font_style = + * { + * element : 'span', + * styles : { 'font-family' : '#(family)' }, + * overrides : [ { element : 'font', attributes : { 'face' : null } } ] + * }; + */ +CKEDITOR.config.font_style = + { + element : 'span', + styles : { 'font-family' : '#(family)' }, + overrides : [ { element : 'font', attributes : { 'face' : null } } ] + }; + +/** + * The list of fonts size to be displayed in the Font Size combo in the + * toolbar. Entries are separated by semi-colons (;). + * + * Any kind of "CSS like" size can be used, like "12px", "2.3em", "130%", + * "larger" or "x-small". + * + * A display name may be optionally defined by prefixing the entries with the + * name and the slash character. For example, "Bigger Font/14px" will be + * displayed as "Bigger Font" in the list, but will be outputted as "14px". + * @type String + * @default '8/8px;9/9px;10/10px;11/11px;12/12px;14/14px;16/16px;18/18px;20/20px;22/22px;24/24px;26/26px;28/28px;36/36px;48/48px;72/72px' + * @example + * config.fontSize_sizes = '16/16px;24/24px;48/48px;'; + * @example + * config.fontSize_sizes = '12px;2.3em;130%;larger;x-small'; + * @example + * config.fontSize_sizes = '12 Pixels/12px;Big/2.3em;30 Percent More/130%;Bigger/larger;Very Small/x-small'; + */ +CKEDITOR.config.fontSize_sizes = + '8/8px;9/9px;10/10px;11/11px;12/12px;14/14px;16/16px;18/18px;20/20px;22/22px;24/24px;26/26px;28/28px;36/36px;48/48px;72/72px'; + +/** + * The text to be displayed in the Font Size combo is none of the available + * values matches the current cursor position or text selection. + * @type String + * @example + * // If the default site font size is 12px, we may making it more explicit to the end user. + * config.fontSize_defaultLabel = '12px'; + */ +CKEDITOR.config.fontSize_defaultLabel = ''; + +/** + * The style definition to be used to apply the font size in the text. + * @type Object + * @example + * // This is actually the default value for it. + * config.fontSize_style = + * { + * element : 'span', + * styles : { 'font-size' : '#(size)' }, + * overrides : [ { element : 'font', attributes : { 'size' : null } } ] + * }; + */ +CKEDITOR.config.fontSize_style = + { + element : 'span', + styles : { 'font-size' : '#(size)' }, + overrides : [ { element : 'font', attributes : { 'size' : null } } ] + }; Index: 3rdParty_sources/ckeditor/plugins/format/plugin.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/plugins/format/plugin.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/plugins/format/plugin.js 17 Aug 2012 14:15:49 -0000 1.1 @@ -0,0 +1,197 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +CKEDITOR.plugins.add( 'format', +{ + requires : [ 'richcombo', 'styles' ], + + init : function( editor ) + { + var config = editor.config, + lang = editor.lang.format; + + // Gets the list of tags from the settings. + var tags = config.format_tags.split( ';' ); + + // Create style objects for all defined styles. + var styles = {}; + for ( var i = 0 ; i < tags.length ; i++ ) + { + var tag = tags[ i ]; + styles[ tag ] = new CKEDITOR.style( config[ 'format_' + tag ] ); + styles[ tag ]._.enterMode = editor.config.enterMode; + } + + editor.ui.addRichCombo( 'Format', + { + label : lang.label, + title : lang.panelTitle, + className : 'cke_format', + panel : + { + css : editor.skin.editor.css.concat( config.contentsCss ), + multiSelect : false, + attributes : { 'aria-label' : lang.panelTitle } + }, + + init : function() + { + this.startGroup( lang.panelTitle ); + + for ( var tag in styles ) + { + var label = lang[ 'tag_' + tag ]; + + // Add the tag entry to the panel list. + this.add( tag, styles[tag].buildPreview( label ), label ); + } + }, + + onClick : function( value ) + { + editor.focus(); + editor.fire( 'saveSnapshot' ); + + var style = styles[ value ], + elementPath = new CKEDITOR.dom.elementPath( editor.getSelection().getStartElement() ); + + style[ style.checkActive( elementPath ) ? 'remove' : 'apply' ]( editor.document ); + + // Save the undo snapshot after all changes are affected. (#4899) + setTimeout( function() + { + editor.fire( 'saveSnapshot' ); + }, 0 ); + }, + + onRender : function() + { + editor.on( 'selectionChange', function( ev ) + { + var currentTag = this.getValue(); + + var elementPath = ev.data.path; + + for ( var tag in styles ) + { + if ( styles[ tag ].checkActive( elementPath ) ) + { + if ( tag != currentTag ) + this.setValue( tag, editor.lang.format[ 'tag_' + tag ] ); + return; + } + } + + // If no styles match, just empty it. + this.setValue( '' ); + }, + this); + } + }); + } +}); + +/** + * A list of semi colon separated style names (by default tags) representing + * the style definition for each entry to be displayed in the Format combo in + * the toolbar. Each entry must have its relative definition configuration in a + * setting named "format_(tagName)". For example, the "p" entry has its + * definition taken from config.format_p. + * @type String + * @default 'p;h1;h2;h3;h4;h5;h6;pre;address;div' + * @example + * config.format_tags = 'p;h2;h3;pre' + */ +CKEDITOR.config.format_tags = 'p;h1;h2;h3;h4;h5;h6;pre;address;div'; + +/** + * The style definition to be used to apply the "Normal" format. + * @type Object + * @default { element : 'p' } + * @example + * config.format_p = { element : 'p', attributes : { 'class' : 'normalPara' } }; + */ +CKEDITOR.config.format_p = { element : 'p' }; + +/** + * The style definition to be used to apply the "Normal (DIV)" format. + * @type Object + * @default { element : 'div' } + * @example + * config.format_div = { element : 'div', attributes : { 'class' : 'normalDiv' } }; + */ +CKEDITOR.config.format_div = { element : 'div' }; + +/** + * The style definition to be used to apply the "Formatted" format. + * @type Object + * @default { element : 'pre' } + * @example + * config.format_pre = { element : 'pre', attributes : { 'class' : 'code' } }; + */ +CKEDITOR.config.format_pre = { element : 'pre' }; + +/** + * The style definition to be used to apply the "Address" format. + * @type Object + * @default { element : 'address' } + * @example + * config.format_address = { element : 'address', attributes : { 'class' : 'styledAddress' } }; + */ +CKEDITOR.config.format_address = { element : 'address' }; + +/** + * The style definition to be used to apply the "Heading 1" format. + * @type Object + * @default { element : 'h1' } + * @example + * config.format_h1 = { element : 'h1', attributes : { 'class' : 'contentTitle1' } }; + */ +CKEDITOR.config.format_h1 = { element : 'h1' }; + +/** + * The style definition to be used to apply the "Heading 1" format. + * @type Object + * @default { element : 'h2' } + * @example + * config.format_h2 = { element : 'h2', attributes : { 'class' : 'contentTitle2' } }; + */ +CKEDITOR.config.format_h2 = { element : 'h2' }; + +/** + * The style definition to be used to apply the "Heading 1" format. + * @type Object + * @default { element : 'h3' } + * @example + * config.format_h3 = { element : 'h3', attributes : { 'class' : 'contentTitle3' } }; + */ +CKEDITOR.config.format_h3 = { element : 'h3' }; + +/** + * The style definition to be used to apply the "Heading 1" format. + * @type Object + * @default { element : 'h4' } + * @example + * config.format_h4 = { element : 'h4', attributes : { 'class' : 'contentTitle4' } }; + */ +CKEDITOR.config.format_h4 = { element : 'h4' }; + +/** + * The style definition to be used to apply the "Heading 1" format. + * @type Object + * @default { element : 'h5' } + * @example + * config.format_h5 = { element : 'h5', attributes : { 'class' : 'contentTitle5' } }; + */ +CKEDITOR.config.format_h5 = { element : 'h5' }; + +/** + * The style definition to be used to apply the "Heading 1" format. + * @type Object + * @default { element : 'h6' } + * @example + * config.format_h6 = { element : 'h6', attributes : { 'class' : 'contentTitle6' } }; + */ +CKEDITOR.config.format_h6 = { element : 'h6' }; Index: 3rdParty_sources/ckeditor/plugins/forms/plugin.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/plugins/forms/plugin.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/plugins/forms/plugin.js 17 Aug 2012 14:15:45 -0000 1.1 @@ -0,0 +1,288 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * @file Forms Plugin + */ + +CKEDITOR.plugins.add( 'forms', +{ + init : function( editor ) + { + var lang = editor.lang; + + editor.addCss( + 'form' + + '{' + + 'border: 1px dotted #FF0000;' + + 'padding: 2px;' + + '}\n' ); + + editor.addCss( + 'img.cke_hidden' + + '{' + + 'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/hiddenfield.gif' ) + ');' + + 'background-position: center center;' + + 'background-repeat: no-repeat;' + + 'border: 1px solid #a9a9a9;' + + 'width: 16px !important;' + + 'height: 16px !important;' + + '}' ); + + // All buttons use the same code to register. So, to avoid + // duplications, let's use this tool function. + var addButtonCommand = function( buttonName, commandName, dialogFile ) + { + editor.addCommand( commandName, new CKEDITOR.dialogCommand( commandName ) ); + + editor.ui.addButton( buttonName, + { + label : lang.common[ buttonName.charAt(0).toLowerCase() + buttonName.slice(1) ], + command : commandName + }); + CKEDITOR.dialog.add( commandName, dialogFile ); + }; + + var dialogPath = this.path + 'dialogs/'; + addButtonCommand( 'Form', 'form', dialogPath + 'form.js' ); + addButtonCommand( 'Checkbox', 'checkbox', dialogPath + 'checkbox.js' ); + addButtonCommand( 'Radio', 'radio', dialogPath + 'radio.js' ); + addButtonCommand( 'TextField', 'textfield', dialogPath + 'textfield.js' ); + addButtonCommand( 'Textarea', 'textarea', dialogPath + 'textarea.js' ); + addButtonCommand( 'Select', 'select', dialogPath + 'select.js' ); + addButtonCommand( 'Button', 'button', dialogPath + 'button.js' ); + addButtonCommand( 'ImageButton', 'imagebutton', CKEDITOR.plugins.getPath('image') + 'dialogs/image.js' ); + addButtonCommand( 'HiddenField', 'hiddenfield', dialogPath + 'hiddenfield.js' ); + + // If the "menu" plugin is loaded, register the menu items. + if ( editor.addMenuItems ) + { + editor.addMenuItems( + { + form : + { + label : lang.form.menu, + command : 'form', + group : 'form' + }, + + checkbox : + { + label : lang.checkboxAndRadio.checkboxTitle, + command : 'checkbox', + group : 'checkbox' + }, + + radio : + { + label : lang.checkboxAndRadio.radioTitle, + command : 'radio', + group : 'radio' + }, + + textfield : + { + label : lang.textfield.title, + command : 'textfield', + group : 'textfield' + }, + + hiddenfield : + { + label : lang.hidden.title, + command : 'hiddenfield', + group : 'hiddenfield' + }, + + imagebutton : + { + label : lang.image.titleButton, + command : 'imagebutton', + group : 'imagebutton' + }, + + button : + { + label : lang.button.title, + command : 'button', + group : 'button' + }, + + select : + { + label : lang.select.title, + command : 'select', + group : 'select' + }, + + textarea : + { + label : lang.textarea.title, + command : 'textarea', + group : 'textarea' + } + }); + } + + // If the "contextmenu" plugin is loaded, register the listeners. + if ( editor.contextMenu ) + { + editor.contextMenu.addListener( function( element ) + { + if ( element && element.hasAscendant( 'form', true ) && !element.isReadOnly() ) + return { form : CKEDITOR.TRISTATE_OFF }; + }); + + editor.contextMenu.addListener( function( element ) + { + if ( element && !element.isReadOnly() ) + { + var name = element.getName(); + + if ( name == 'select' ) + return { select : CKEDITOR.TRISTATE_OFF }; + + if ( name == 'textarea' ) + return { textarea : CKEDITOR.TRISTATE_OFF }; + + if ( name == 'input' ) + { + switch( element.getAttribute( 'type' ) ) + { + case 'button' : + case 'submit' : + case 'reset' : + return { button : CKEDITOR.TRISTATE_OFF }; + + case 'checkbox' : + return { checkbox : CKEDITOR.TRISTATE_OFF }; + + case 'radio' : + return { radio : CKEDITOR.TRISTATE_OFF }; + + case 'image' : + return { imagebutton : CKEDITOR.TRISTATE_OFF }; + + default : + return { textfield : CKEDITOR.TRISTATE_OFF }; + } + } + + if ( name == 'img' && element.data( 'cke-real-element-type' ) == 'hiddenfield' ) + return { hiddenfield : CKEDITOR.TRISTATE_OFF }; + } + }); + } + + editor.on( 'doubleclick', function( evt ) + { + var element = evt.data.element; + + if ( element.is( 'form' ) ) + evt.data.dialog = 'form'; + else if ( element.is( 'select' ) ) + evt.data.dialog = 'select'; + else if ( element.is( 'textarea' ) ) + evt.data.dialog = 'textarea'; + else if ( element.is( 'img' ) && element.data( 'cke-real-element-type' ) == 'hiddenfield' ) + evt.data.dialog = 'hiddenfield'; + else if ( element.is( 'input' ) ) + { + switch ( element.getAttribute( 'type' ) ) + { + case 'button' : + case 'submit' : + case 'reset' : + evt.data.dialog = 'button'; + break; + case 'checkbox' : + evt.data.dialog = 'checkbox'; + break; + case 'radio' : + evt.data.dialog = 'radio'; + break; + case 'image' : + evt.data.dialog = 'imagebutton'; + break; + default : + evt.data.dialog = 'textfield'; + break; + } + } + }); + }, + + afterInit : function( editor ) + { + var dataProcessor = editor.dataProcessor, + htmlFilter = dataProcessor && dataProcessor.htmlFilter, + dataFilter = dataProcessor && dataProcessor.dataFilter; + + // Cleanup certain IE form elements default values. + if ( CKEDITOR.env.ie ) + { + htmlFilter && htmlFilter.addRules( + { + elements : + { + input : function( input ) + { + var attrs = input.attributes, + type = attrs.type; + // Old IEs don't provide type for Text inputs #5522 + if ( !type ) + attrs.type = 'text'; + if ( type == 'checkbox' || type == 'radio' ) + attrs.value == 'on' && delete attrs.value; + } + } + } ); + } + + if ( dataFilter ) + { + dataFilter.addRules( + { + elements : + { + input : function( element ) + { + if ( element.attributes.type == 'hidden' ) + return editor.createFakeParserElement( element, 'cke_hidden', 'hiddenfield' ); + } + } + } ); + } + }, + requires : [ 'image', 'fakeobjects' ] +} ); + +if ( CKEDITOR.env.ie ) +{ + CKEDITOR.dom.element.prototype.hasAttribute = CKEDITOR.tools.override( CKEDITOR.dom.element.prototype.hasAttribute, + function( original ) + { + return function( name ) + { + var $attr = this.$.attributes.getNamedItem( name ); + + if ( this.getName() == 'input' ) + { + switch ( name ) + { + case 'class' : + return this.$.className.length > 0; + case 'checked' : + return !!this.$.checked; + case 'value' : + var type = this.getAttribute( 'type' ); + return type == 'checkbox' || type == 'radio' ? this.$.value != 'on' : this.$.value; + } + } + + return original.apply( this, arguments ); + }; + }); +} Index: 3rdParty_sources/ckeditor/plugins/forms/dialogs/button.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/plugins/forms/dialogs/button.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/plugins/forms/dialogs/button.js 17 Aug 2012 14:15:44 -0000 1.1 @@ -0,0 +1,118 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ +CKEDITOR.dialog.add( 'button', function( editor ) +{ + function commitAttributes( element ) + { + var val = this.getValue(); + if ( val ) + { + element.attributes[ this.id ] = val; + if ( this.id == 'name' ) + element.attributes[ 'data-cke-saved-name' ] = val; + } + else + { + delete element.attributes[ this.id ]; + if ( this.id == 'name' ) + delete element.attributes[ 'data-cke-saved-name' ]; + } + } + + return { + title : editor.lang.button.title, + minWidth : 350, + minHeight : 150, + onShow : function() + { + delete this.button; + var element = this.getParentEditor().getSelection().getSelectedElement(); + if ( element && element.is( 'input' ) ) + { + var type = element.getAttribute( 'type' ); + if ( type in { button:1, reset:1, submit:1 } ) + { + this.button = element; + this.setupContent( element ); + } + } + }, + onOk : function() + { + var editor = this.getParentEditor(), + element = this.button, + isInsertMode = !element; + + var fake = element ? CKEDITOR.htmlParser.fragment.fromHtml( element.getOuterHtml() ).children[ 0 ] + : new CKEDITOR.htmlParser.element( 'input' ); + this.commitContent( fake ); + + var writer = new CKEDITOR.htmlParser.basicWriter(); + fake.writeHtml( writer ); + var newElement = CKEDITOR.dom.element.createFromHtml( writer.getHtml(), editor.document ); + + if ( isInsertMode ) + editor.insertElement( newElement ); + else + { + newElement.replace( element ); + editor.getSelection().selectElement( newElement ); + } + }, + contents : [ + { + id : 'info', + label : editor.lang.button.title, + title : editor.lang.button.title, + elements : [ + { + id : 'name', + type : 'text', + label : editor.lang.common.name, + 'default' : '', + setup : function( element ) + { + this.setValue( + element.data( 'cke-saved-name' ) || + element.getAttribute( 'name' ) || + '' ); + }, + commit : commitAttributes + }, + { + id : 'value', + type : 'text', + label : editor.lang.button.text, + accessKey : 'V', + 'default' : '', + setup : function( element ) + { + this.setValue( element.getAttribute( 'value' ) || '' ); + }, + commit : commitAttributes + }, + { + id : 'type', + type : 'select', + label : editor.lang.button.type, + 'default' : 'button', + accessKey : 'T', + items : + [ + [ editor.lang.button.typeBtn, 'button' ], + [ editor.lang.button.typeSbm, 'submit' ], + [ editor.lang.button.typeRst, 'reset' ] + ], + setup : function( element ) + { + this.setValue( element.getAttribute( 'type' ) || '' ); + }, + commit : commitAttributes + } + ] + } + ] + }; +}); Index: 3rdParty_sources/ckeditor/plugins/forms/dialogs/checkbox.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/plugins/forms/dialogs/checkbox.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/plugins/forms/dialogs/checkbox.js 17 Aug 2012 14:15:44 -0000 1.1 @@ -0,0 +1,153 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ +CKEDITOR.dialog.add( 'checkbox', function( editor ) +{ + return { + title : editor.lang.checkboxAndRadio.checkboxTitle, + minWidth : 350, + minHeight : 140, + onShow : function() + { + delete this.checkbox; + + var element = this.getParentEditor().getSelection().getSelectedElement(); + + if ( element && element.getAttribute( 'type' ) == 'checkbox' ) + { + this.checkbox = element; + this.setupContent( element ); + } + }, + onOk : function() + { + var editor, + element = this.checkbox, + isInsertMode = !element; + + if ( isInsertMode ) + { + editor = this.getParentEditor(); + element = editor.document.createElement( 'input' ); + element.setAttribute( 'type', 'checkbox' ); + editor.insertElement( element ); + } + this.commitContent( { element : element } ); + }, + contents : [ + { + id : 'info', + label : editor.lang.checkboxAndRadio.checkboxTitle, + title : editor.lang.checkboxAndRadio.checkboxTitle, + startupFocus : 'txtName', + elements : [ + { + id : 'txtName', + type : 'text', + label : editor.lang.common.name, + 'default' : '', + accessKey : 'N', + setup : function( element ) + { + this.setValue( + element.data( 'cke-saved-name' ) || + element.getAttribute( 'name' ) || + '' ); + }, + commit : function( data ) + { + var element = data.element; + + // IE failed to update 'name' property on input elements, protect it now. + if ( this.getValue() ) + element.data( 'cke-saved-name', this.getValue() ); + else + { + element.data( 'cke-saved-name', false ); + element.removeAttribute( 'name' ); + } + } + }, + { + id : 'txtValue', + type : 'text', + label : editor.lang.checkboxAndRadio.value, + 'default' : '', + accessKey : 'V', + setup : function( element ) + { + var value = element.getAttribute( 'value' ); + // IE Return 'on' as default attr value. + this.setValue( CKEDITOR.env.ie && value == 'on' ? '' : value ); + }, + commit : function( data ) + { + var element = data.element, + value = this.getValue(); + + if ( value && !( CKEDITOR.env.ie && value == 'on' ) ) + element.setAttribute( 'value', value ); + else + { + if ( CKEDITOR.env.ie ) + { + // Remove attribute 'value' of checkbox (#4721). + var checkbox = new CKEDITOR.dom.element( 'input', element.getDocument() ); + element.copyAttributes( checkbox, { value: 1 } ); + checkbox.replace( element ); + editor.getSelection().selectElement( checkbox ); + data.element = checkbox; + } + else + element.removeAttribute( 'value' ); + } + } + }, + { + id : 'cmbSelected', + type : 'checkbox', + label : editor.lang.checkboxAndRadio.selected, + 'default' : '', + accessKey : 'S', + value : "checked", + setup : function( element ) + { + this.setValue( element.getAttribute( 'checked' ) ); + }, + commit : function( data ) + { + var element = data.element; + + if ( CKEDITOR.env.ie ) + { + var isElementChecked = !!element.getAttribute( 'checked' ), + isChecked = !!this.getValue(); + + if ( isElementChecked != isChecked ) + { + var replace = CKEDITOR.dom.element.createFromHtml( '', editor.document ); + + element.copyAttributes( replace, { type : 1, checked : 1 } ); + replace.replace( element ); + editor.getSelection().selectElement( replace ); + data.element = replace; + } + } + else + { + var value = this.getValue(); + if ( value ) + element.setAttribute( 'checked', 'checked' ); + else + element.removeAttribute( 'checked' ); + } + } + } + ] + } + ] + }; +}); Index: 3rdParty_sources/ckeditor/plugins/forms/dialogs/form.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/plugins/forms/dialogs/form.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/plugins/forms/dialogs/form.js 17 Aug 2012 14:15:44 -0000 1.1 @@ -0,0 +1,177 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ +CKEDITOR.dialog.add( 'form', function( editor ) +{ + var autoAttributes = + { + action : 1, + id : 1, + method : 1, + enctype : 1, + target : 1 + }; + + return { + title : editor.lang.form.title, + minWidth : 350, + minHeight : 200, + onShow : function() + { + delete this.form; + + var element = this.getParentEditor().getSelection().getStartElement(); + var form = element && element.getAscendant( 'form', true ); + if ( form ) + { + this.form = form; + this.setupContent( form ); + } + }, + onOk : function() + { + var editor, + element = this.form, + isInsertMode = !element; + + if ( isInsertMode ) + { + editor = this.getParentEditor(); + element = editor.document.createElement( 'form' ); + !CKEDITOR.env.ie && element.append( editor.document.createElement( 'br' ) ); + } + + if ( isInsertMode ) + editor.insertElement( element ); + this.commitContent( element ); + }, + onLoad : function() + { + function autoSetup( element ) + { + this.setValue( element.getAttribute( this.id ) || '' ); + } + + function autoCommit( element ) + { + if ( this.getValue() ) + element.setAttribute( this.id, this.getValue() ); + else + element.removeAttribute( this.id ); + } + + this.foreach( function( contentObj ) + { + if ( autoAttributes[ contentObj.id ] ) + { + contentObj.setup = autoSetup; + contentObj.commit = autoCommit; + } + } ); + }, + contents : [ + { + id : 'info', + label : editor.lang.form.title, + title : editor.lang.form.title, + elements : [ + { + id : 'txtName', + type : 'text', + label : editor.lang.common.name, + 'default' : '', + accessKey : 'N', + setup : function( element ) + { + this.setValue( element.data( 'cke-saved-name' ) || + element.getAttribute( 'name' ) || + '' ); + }, + commit : function( element ) + { + if ( this.getValue() ) + element.data( 'cke-saved-name', this.getValue() ); + else + { + element.data( 'cke-saved-name', false ); + element.removeAttribute( 'name' ); + } + } + }, + { + id : 'action', + type : 'text', + label : editor.lang.form.action, + 'default' : '', + accessKey : 'T' + }, + { + type : 'hbox', + widths : [ '45%', '55%' ], + children : + [ + { + id : 'id', + type : 'text', + label : editor.lang.common.id, + 'default' : '', + accessKey : 'I' + }, + { + id : 'enctype', + type : 'select', + label : editor.lang.form.encoding, + style : 'width:100%', + accessKey : 'E', + 'default' : '', + items : + [ + [ '' ], + [ 'text/plain' ], + [ 'multipart/form-data' ], + [ 'application/x-www-form-urlencoded' ] + ] + } + ] + }, + { + type : 'hbox', + widths : [ '45%', '55%' ], + children : + [ + { + id : 'target', + type : 'select', + label : editor.lang.common.target, + style : 'width:100%', + accessKey : 'M', + 'default' : '', + items : + [ + [ editor.lang.common.notSet, '' ], + [ editor.lang.common.targetNew, '_blank' ], + [ editor.lang.common.targetTop, '_top' ], + [ editor.lang.common.targetSelf, '_self' ], + [ editor.lang.common.targetParent, '_parent' ] + ] + }, + { + id : 'method', + type : 'select', + label : editor.lang.form.method, + accessKey : 'M', + 'default' : 'GET', + items : + [ + [ 'GET', 'get' ], + [ 'POST', 'post' ] + ] + } + ] + } + ] + } + ] + }; +}); Index: 3rdParty_sources/ckeditor/plugins/forms/dialogs/hiddenfield.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/plugins/forms/dialogs/hiddenfield.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/plugins/forms/dialogs/hiddenfield.js 17 Aug 2012 14:15:44 -0000 1.1 @@ -0,0 +1,100 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ +CKEDITOR.dialog.add( 'hiddenfield', function( editor ) +{ + return { + title : editor.lang.hidden.title, + hiddenField : null, + minWidth : 350, + minHeight : 110, + onShow : function() + { + delete this.hiddenField; + + var editor = this.getParentEditor(), + selection = editor.getSelection(), + element = selection.getSelectedElement(); + + if ( element && element.data( 'cke-real-element-type' ) && element.data( 'cke-real-element-type' ) == 'hiddenfield' ) + { + this.hiddenField = element; + element = editor.restoreRealElement( this.hiddenField ); + this.setupContent( element ); + selection.selectElement( this.hiddenField ); + } + }, + onOk : function() + { + var name = this.getValueOf( 'info', '_cke_saved_name' ), + value = this.getValueOf( 'info', 'value' ), + editor = this.getParentEditor(), + element = CKEDITOR.env.ie && !( CKEDITOR.document.$.documentMode >= 8 ) ? + editor.document.createElement( '' ) + : editor.document.createElement( 'input' ); + + element.setAttribute( 'type', 'hidden' ); + this.commitContent( element ); + var fakeElement = editor.createFakeElement( element, 'cke_hidden', 'hiddenfield' ); + if ( !this.hiddenField ) + editor.insertElement( fakeElement ); + else + { + fakeElement.replace( this.hiddenField ); + editor.getSelection().selectElement( fakeElement ); + } + return true; + }, + contents : [ + { + id : 'info', + label : editor.lang.hidden.title, + title : editor.lang.hidden.title, + elements : [ + { + id : '_cke_saved_name', + type : 'text', + label : editor.lang.hidden.name, + 'default' : '', + accessKey : 'N', + setup : function( element ) + { + this.setValue( + element.data( 'cke-saved-name' ) || + element.getAttribute( 'name' ) || + '' ); + }, + commit : function( element ) + { + if ( this.getValue() ) + element.setAttribute( 'name', this.getValue() ); + else + { + element.removeAttribute( 'name' ); + } + } + }, + { + id : 'value', + type : 'text', + label : editor.lang.hidden.value, + 'default' : '', + accessKey : 'V', + setup : function( element ) + { + this.setValue( element.getAttribute( 'value' ) || '' ); + }, + commit : function( element ) + { + if ( this.getValue() ) + element.setAttribute( 'value', this.getValue() ); + else + element.removeAttribute( 'value' ); + } + } + ] + } + ] + }; +}); Index: 3rdParty_sources/ckeditor/plugins/forms/dialogs/radio.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/plugins/forms/dialogs/radio.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/plugins/forms/dialogs/radio.js 17 Aug 2012 14:15:44 -0000 1.1 @@ -0,0 +1,135 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ +CKEDITOR.dialog.add( 'radio', function( editor ) +{ + return { + title : editor.lang.checkboxAndRadio.radioTitle, + minWidth : 350, + minHeight : 140, + onShow : function() + { + delete this.radioButton; + + var element = this.getParentEditor().getSelection().getSelectedElement(); + if ( element && element.getName() == 'input' && element.getAttribute( 'type' ) == 'radio' ) + { + this.radioButton = element; + this.setupContent( element ); + } + }, + onOk : function() + { + var editor, + element = this.radioButton, + isInsertMode = !element; + + if ( isInsertMode ) + { + editor = this.getParentEditor(); + element = editor.document.createElement( 'input' ); + element.setAttribute( 'type', 'radio' ); + } + + if ( isInsertMode ) + editor.insertElement( element ); + this.commitContent( { element : element } ); + }, + contents : [ + { + id : 'info', + label : editor.lang.checkboxAndRadio.radioTitle, + title : editor.lang.checkboxAndRadio.radioTitle, + elements : [ + { + id : 'name', + type : 'text', + label : editor.lang.common.name, + 'default' : '', + accessKey : 'N', + setup : function( element ) + { + this.setValue( + element.data( 'cke-saved-name' ) || + element.getAttribute( 'name' ) || + '' ); + }, + commit : function( data ) + { + var element = data.element; + + if ( this.getValue() ) + element.data( 'cke-saved-name', this.getValue() ); + else + { + element.data( 'cke-saved-name', false ); + element.removeAttribute( 'name' ); + } + } + }, + { + id : 'value', + type : 'text', + label : editor.lang.checkboxAndRadio.value, + 'default' : '', + accessKey : 'V', + setup : function( element ) + { + this.setValue( element.getAttribute( 'value' ) || '' ); + }, + commit : function( data ) + { + var element = data.element; + + if ( this.getValue() ) + element.setAttribute( 'value', this.getValue() ); + else + element.removeAttribute( 'value' ); + } + }, + { + id : 'checked', + type : 'checkbox', + label : editor.lang.checkboxAndRadio.selected, + 'default' : '', + accessKey : 'S', + value : "checked", + setup : function( element ) + { + this.setValue( element.getAttribute( 'checked' ) ); + }, + commit : function( data ) + { + var element = data.element; + + if ( !( CKEDITOR.env.ie || CKEDITOR.env.opera ) ) + { + if ( this.getValue() ) + element.setAttribute( 'checked', 'checked' ); + else + element.removeAttribute( 'checked' ); + } + else + { + var isElementChecked = element.getAttribute( 'checked' ); + var isChecked = !!this.getValue(); + + if ( isElementChecked != isChecked ) + { + var replace = CKEDITOR.dom.element.createFromHtml( '', editor.document ); + element.copyAttributes( replace, { type : 1, checked : 1 } ); + replace.replace( element ); + editor.getSelection().selectElement( replace ); + data.element = replace; + } + } + } + } + ] + } + ] + }; +}); Index: 3rdParty_sources/ckeditor/plugins/forms/dialogs/select.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/plugins/forms/dialogs/select.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/plugins/forms/dialogs/select.js 17 Aug 2012 14:15:44 -0000 1.1 @@ -0,0 +1,558 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ +CKEDITOR.dialog.add( 'select', function( editor ) +{ + // Add a new option to a SELECT object (combo or list). + function addOption( combo, optionText, optionValue, documentObject, index ) + { + combo = getSelect( combo ); + var oOption; + if ( documentObject ) + oOption = documentObject.createElement( "OPTION" ); + else + oOption = document.createElement( "OPTION" ); + + if ( combo && oOption && oOption.getName() == 'option' ) + { + if ( CKEDITOR.env.ie ) { + if ( !isNaN( parseInt( index, 10) ) ) + combo.$.options.add( oOption.$, index ); + else + combo.$.options.add( oOption.$ ); + + oOption.$.innerHTML = optionText.length > 0 ? optionText : ''; + oOption.$.value = optionValue; + } + else + { + if ( index !== null && index < combo.getChildCount() ) + combo.getChild( index < 0 ? 0 : index ).insertBeforeMe( oOption ); + else + combo.append( oOption ); + + oOption.setText( optionText.length > 0 ? optionText : '' ); + oOption.setValue( optionValue ); + } + } + else + return false; + + return oOption; + } + // Remove all selected options from a SELECT object. + function removeSelectedOptions( combo ) + { + combo = getSelect( combo ); + + // Save the selected index + var iSelectedIndex = getSelectedIndex( combo ); + + // Remove all selected options. + for ( var i = combo.getChildren().count() - 1 ; i >= 0 ; i-- ) + { + if ( combo.getChild( i ).$.selected ) + combo.getChild( i ).remove(); + } + + // Reset the selection based on the original selected index. + setSelectedIndex( combo, iSelectedIndex ); + } + //Modify option from a SELECT object. + function modifyOption( combo, index, title, value ) + { + combo = getSelect( combo ); + if ( index < 0 ) + return false; + var child = combo.getChild( index ); + child.setText( title ); + child.setValue( value ); + return child; + } + function removeAllOptions( combo ) + { + combo = getSelect( combo ); + while ( combo.getChild( 0 ) && combo.getChild( 0 ).remove() ) + { /*jsl:pass*/ } + } + // Moves the selected option by a number of steps (also negative). + function changeOptionPosition( combo, steps, documentObject ) + { + combo = getSelect( combo ); + var iActualIndex = getSelectedIndex( combo ); + if ( iActualIndex < 0 ) + return false; + + var iFinalIndex = iActualIndex + steps; + iFinalIndex = ( iFinalIndex < 0 ) ? 0 : iFinalIndex; + iFinalIndex = ( iFinalIndex >= combo.getChildCount() ) ? combo.getChildCount() - 1 : iFinalIndex; + + if ( iActualIndex == iFinalIndex ) + return false; + + var oOption = combo.getChild( iActualIndex ), + sText = oOption.getText(), + sValue = oOption.getValue(); + + oOption.remove(); + + oOption = addOption( combo, sText, sValue, ( !documentObject ) ? null : documentObject, iFinalIndex ); + setSelectedIndex( combo, iFinalIndex ); + return oOption; + } + function getSelectedIndex( combo ) + { + combo = getSelect( combo ); + return combo ? combo.$.selectedIndex : -1; + } + function setSelectedIndex( combo, index ) + { + combo = getSelect( combo ); + if ( index < 0 ) + return null; + var count = combo.getChildren().count(); + combo.$.selectedIndex = ( index >= count ) ? ( count - 1 ) : index; + return combo; + } + function getOptions( combo ) + { + combo = getSelect( combo ); + return combo ? combo.getChildren() : false; + } + function getSelect( obj ) + { + if ( obj && obj.domId && obj.getInputElement().$ ) // Dialog element. + return obj.getInputElement(); + else if ( obj && obj.$ ) + return obj; + return false; + } + + return { + title : editor.lang.select.title, + minWidth : CKEDITOR.env.ie ? 460 : 395, + minHeight : CKEDITOR.env.ie ? 320 : 300, + onShow : function() + { + delete this.selectBox; + this.setupContent( 'clear' ); + var element = this.getParentEditor().getSelection().getSelectedElement(); + if ( element && element.getName() == "select" ) + { + this.selectBox = element; + this.setupContent( element.getName(), element ); + + // Load Options into dialog. + var objOptions = getOptions( element ); + for ( var i = 0 ; i < objOptions.count() ; i++ ) + this.setupContent( 'option', objOptions.getItem( i ) ); + } + }, + onOk : function() + { + var editor = this.getParentEditor(), + element = this.selectBox, + isInsertMode = !element; + + if ( isInsertMode ) + element = editor.document.createElement( 'select' ); + this.commitContent( element ); + + if ( isInsertMode ) + { + editor.insertElement( element ); + if ( CKEDITOR.env.ie ) + { + var sel = editor.getSelection(), + bms = sel.createBookmarks(); + setTimeout(function() + { + sel.selectBookmarks( bms ); + }, 0 ); + } + } + }, + contents : [ + { + id : 'info', + label : editor.lang.select.selectInfo, + title : editor.lang.select.selectInfo, + accessKey : '', + elements : [ + { + id : 'txtName', + type : 'text', + widths : [ '25%','75%' ], + labelLayout : 'horizontal', + label : editor.lang.common.name, + 'default' : '', + accessKey : 'N', + style : 'width:350px', + setup : function( name, element ) + { + if ( name == 'clear' ) + this.setValue( this[ 'default' ] || '' ); + else if ( name == 'select' ) + { + this.setValue( + element.data( 'cke-saved-name' ) || + element.getAttribute( 'name' ) || + '' ); + } + }, + commit : function( element ) + { + if ( this.getValue() ) + element.data( 'cke-saved-name', this.getValue() ); + else + { + element.data( 'cke-saved-name', false ); + element.removeAttribute( 'name' ); + } + } + }, + { + id : 'txtValue', + type : 'text', + widths : [ '25%','75%' ], + labelLayout : 'horizontal', + label : editor.lang.select.value, + style : 'width:350px', + 'default' : '', + className : 'cke_disabled', + onLoad : function() + { + this.getInputElement().setAttribute( 'readOnly', true ); + }, + setup : function( name, element ) + { + if ( name == 'clear' ) + this.setValue( '' ); + else if ( name == 'option' && element.getAttribute( 'selected' ) ) + this.setValue( element.$.value ); + } + }, + { + type : 'hbox', + widths : [ '175px', '170px' ], + children : + [ + { + id : 'txtSize', + type : 'text', + labelLayout : 'horizontal', + label : editor.lang.select.size, + 'default' : '', + accessKey : 'S', + style : 'width:175px', + validate: function() + { + var func = CKEDITOR.dialog.validate.integer( editor.lang.common.validateNumberFailed ); + return ( ( this.getValue() === '' ) || func.apply( this ) ); + }, + setup : function( name, element ) + { + if ( name == 'select' ) + this.setValue( element.getAttribute( 'size' ) || '' ); + if ( CKEDITOR.env.webkit ) + this.getInputElement().setStyle( 'width', '86px' ); + }, + commit : function( element ) + { + if ( this.getValue() ) + element.setAttribute( 'size', this.getValue() ); + else + element.removeAttribute( 'size' ); + } + }, + { + type : 'html', + html : '' + CKEDITOR.tools.htmlEncode( editor.lang.select.lines ) + '' + } + ] + }, + { + type : 'html', + html : '' + CKEDITOR.tools.htmlEncode( editor.lang.select.opAvail ) + '' + }, + { + type : 'hbox', + widths : [ '115px', '115px' ,'100px' ], + children : + [ + { + type : 'vbox', + children : + [ + { + id : 'txtOptName', + type : 'text', + label : editor.lang.select.opText, + style : 'width:115px', + setup : function( name, element ) + { + if ( name == 'clear' ) + this.setValue( "" ); + } + }, + { + type : 'select', + id : 'cmbName', + label : '', + title : '', + size : 5, + style : 'width:115px;height:75px', + items : [], + onChange : function() + { + var dialog = this.getDialog(), + values = dialog.getContentElement( 'info', 'cmbValue' ), + optName = dialog.getContentElement( 'info', 'txtOptName' ), + optValue = dialog.getContentElement( 'info', 'txtOptValue' ), + iIndex = getSelectedIndex( this ); + + setSelectedIndex( values, iIndex ); + optName.setValue( this.getValue() ); + optValue.setValue( values.getValue() ); + }, + setup : function( name, element ) + { + if ( name == 'clear' ) + removeAllOptions( this ); + else if ( name == 'option' ) + addOption( this, element.getText(), element.getText(), + this.getDialog().getParentEditor().document ); + }, + commit : function( element ) + { + var dialog = this.getDialog(), + optionsNames = getOptions( this ), + optionsValues = getOptions( dialog.getContentElement( 'info', 'cmbValue' ) ), + selectValue = dialog.getContentElement( 'info', 'txtValue' ).getValue(); + + removeAllOptions( element ); + + for ( var i = 0 ; i < optionsNames.count() ; i++ ) + { + var oOption = addOption( element, optionsNames.getItem( i ).getValue(), + optionsValues.getItem( i ).getValue(), dialog.getParentEditor().document ); + if ( optionsValues.getItem( i ).getValue() == selectValue ) + { + oOption.setAttribute( 'selected', 'selected' ); + oOption.selected = true; + } + } + } + } + ] + }, + { + type : 'vbox', + children : + [ + { + id : 'txtOptValue', + type : 'text', + label : editor.lang.select.opValue, + style : 'width:115px', + setup : function( name, element ) + { + if ( name == 'clear' ) + this.setValue( "" ); + } + }, + { + type : 'select', + id : 'cmbValue', + label : '', + size : 5, + style : 'width:115px;height:75px', + items : [], + onChange : function() + { + var dialog = this.getDialog(), + names = dialog.getContentElement( 'info', 'cmbName' ), + optName = dialog.getContentElement( 'info', 'txtOptName' ), + optValue = dialog.getContentElement( 'info', 'txtOptValue' ), + iIndex = getSelectedIndex( this ); + + setSelectedIndex( names, iIndex ); + optName.setValue( names.getValue() ); + optValue.setValue( this.getValue() ); + }, + setup : function( name, element ) + { + if ( name == 'clear' ) + removeAllOptions( this ); + else if ( name == 'option' ) + { + var oValue = element.getValue(); + addOption( this, oValue, oValue, + this.getDialog().getParentEditor().document ); + if ( element.getAttribute( 'selected' ) == 'selected' ) + this.getDialog().getContentElement( 'info', 'txtValue' ).setValue( oValue ); + } + } + } + ] + }, + { + type : 'vbox', + padding : 5, + children : + [ + { + type : 'button', + id : 'btnAdd', + style : '', + label : editor.lang.select.btnAdd, + title : editor.lang.select.btnAdd, + style : 'width:100%;', + onClick : function() + { + //Add new option. + var dialog = this.getDialog(), + parentEditor = dialog.getParentEditor(), + optName = dialog.getContentElement( 'info', 'txtOptName' ), + optValue = dialog.getContentElement( 'info', 'txtOptValue' ), + names = dialog.getContentElement( 'info', 'cmbName' ), + values = dialog.getContentElement( 'info', 'cmbValue' ); + + addOption(names, optName.getValue(), optName.getValue(), dialog.getParentEditor().document ); + addOption(values, optValue.getValue(), optValue.getValue(), dialog.getParentEditor().document ); + + optName.setValue( "" ); + optValue.setValue( "" ); + } + }, + { + type : 'button', + id : 'btnModify', + label : editor.lang.select.btnModify, + title : editor.lang.select.btnModify, + style : 'width:100%;', + onClick : function() + { + //Modify selected option. + var dialog = this.getDialog(), + optName = dialog.getContentElement( 'info', 'txtOptName' ), + optValue = dialog.getContentElement( 'info', 'txtOptValue' ), + names = dialog.getContentElement( 'info', 'cmbName' ), + values = dialog.getContentElement( 'info', 'cmbValue' ), + iIndex = getSelectedIndex( names ); + + if ( iIndex >= 0 ) + { + modifyOption( names, iIndex, optName.getValue(), optName.getValue() ); + modifyOption( values, iIndex, optValue.getValue(), optValue.getValue() ); + } + } + }, + { + type : 'button', + id : 'btnUp', + style : 'width:100%;', + label : editor.lang.select.btnUp, + title : editor.lang.select.btnUp, + onClick : function() + { + //Move up. + var dialog = this.getDialog(), + names = dialog.getContentElement( 'info', 'cmbName' ), + values = dialog.getContentElement( 'info', 'cmbValue' ); + + changeOptionPosition( names, -1, dialog.getParentEditor().document ); + changeOptionPosition( values, -1, dialog.getParentEditor().document ); + } + }, + { + type : 'button', + id : 'btnDown', + style : 'width:100%;', + label : editor.lang.select.btnDown, + title : editor.lang.select.btnDown, + onClick : function() + { + //Move down. + var dialog = this.getDialog(), + names = dialog.getContentElement( 'info', 'cmbName' ), + values = dialog.getContentElement( 'info', 'cmbValue' ); + + changeOptionPosition( names, 1, dialog.getParentEditor().document ); + changeOptionPosition( values, 1, dialog.getParentEditor().document ); + } + } + ] + } + ] + }, + { + type : 'hbox', + widths : [ '40%', '20%', '40%' ], + children : + [ + { + type : 'button', + id : 'btnSetValue', + label : editor.lang.select.btnSetValue, + title : editor.lang.select.btnSetValue, + onClick : function() + { + //Set as default value. + var dialog = this.getDialog(), + values = dialog.getContentElement( 'info', 'cmbValue' ), + txtValue = dialog.getContentElement( 'info', 'txtValue' ); + txtValue.setValue( values.getValue() ); + } + }, + { + type : 'button', + id : 'btnDelete', + label : editor.lang.select.btnDelete, + title : editor.lang.select.btnDelete, + onClick : function() + { + // Delete option. + var dialog = this.getDialog(), + names = dialog.getContentElement( 'info', 'cmbName' ), + values = dialog.getContentElement( 'info', 'cmbValue' ), + optName = dialog.getContentElement( 'info', 'txtOptName' ), + optValue = dialog.getContentElement( 'info', 'txtOptValue' ); + + removeSelectedOptions( names ); + removeSelectedOptions( values ); + + optName.setValue( "" ); + optValue.setValue( "" ); + } + }, + { + id : 'chkMulti', + type : 'checkbox', + label : editor.lang.select.chkMulti, + 'default' : '', + accessKey : 'M', + value : "checked", + setup : function( name, element ) + { + if ( name == 'select' ) + this.setValue( element.getAttribute( 'multiple' ) ); + if ( CKEDITOR.env.webkit ) + this.getElement().getParent().setStyle( 'vertical-align', 'middle' ); + }, + commit : function( element ) + { + if ( this.getValue() ) + element.setAttribute( 'multiple', this.getValue() ); + else + element.removeAttribute( 'multiple' ); + } + } + ] + } + ] + } + ] + }; +}); Index: 3rdParty_sources/ckeditor/plugins/forms/dialogs/textarea.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/plugins/forms/dialogs/textarea.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/plugins/forms/dialogs/textarea.js 17 Aug 2012 14:15:44 -0000 1.1 @@ -0,0 +1,135 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ +CKEDITOR.dialog.add( 'textarea', function( editor ) +{ + return { + title : editor.lang.textarea.title, + minWidth : 350, + minHeight : 220, + onShow : function() + { + delete this.textarea; + + var element = this.getParentEditor().getSelection().getSelectedElement(); + if ( element && element.getName() == "textarea" ) + { + this.textarea = element; + this.setupContent( element ); + } + }, + onOk : function() + { + var editor, + element = this.textarea, + isInsertMode = !element; + + if ( isInsertMode ) + { + editor = this.getParentEditor(); + element = editor.document.createElement( 'textarea' ); + } + this.commitContent( element ); + + if ( isInsertMode ) + editor.insertElement( element ); + }, + contents : [ + { + id : 'info', + label : editor.lang.textarea.title, + title : editor.lang.textarea.title, + elements : [ + { + id : '_cke_saved_name', + type : 'text', + label : editor.lang.common.name, + 'default' : '', + accessKey : 'N', + setup : function( element ) + { + this.setValue( + element.data( 'cke-saved-name' ) || + element.getAttribute( 'name' ) || + '' ); + }, + commit : function( element ) + { + if ( this.getValue() ) + element.data( 'cke-saved-name', this.getValue() ); + else + { + element.data( 'cke-saved-name', false ); + element.removeAttribute( 'name' ); + } + } + }, + { + type : 'hbox', + widths:['50%','50%'], + children:[ + { + id : 'cols', + type : 'text', + label : editor.lang.textarea.cols, + 'default' : '', + accessKey : 'C', + style : 'width:50px', + validate : CKEDITOR.dialog.validate.integer( editor.lang.common.validateNumberFailed ), + setup : function( element ) + { + var value = element.hasAttribute( 'cols' ) && element.getAttribute( 'cols' ); + this.setValue( value || '' ); + }, + commit : function( element ) + { + if ( this.getValue() ) + element.setAttribute( 'cols', this.getValue() ); + else + element.removeAttribute( 'cols' ); + } + }, + { + id : 'rows', + type : 'text', + label : editor.lang.textarea.rows, + 'default' : '', + accessKey : 'R', + style : 'width:50px', + validate : CKEDITOR.dialog.validate.integer( editor.lang.common.validateNumberFailed ), + setup : function( element ) + { + var value = element.hasAttribute( 'rows' ) && element.getAttribute( 'rows' ); + this.setValue( value || '' ); + }, + commit : function( element ) + { + if ( this.getValue() ) + element.setAttribute( 'rows', this.getValue() ); + else + element.removeAttribute( 'rows' ); + } + } + ] + }, + { + id : 'value', + type : 'textarea', + label : editor.lang.textfield.value, + 'default' : '', + setup : function( element ) + { + this.setValue( element.$.defaultValue ); + }, + commit : function( element ) + { + element.$.value = element.$.defaultValue = this.getValue() ; + } + } + + ] + } + ] + }; +}); Index: 3rdParty_sources/ckeditor/plugins/forms/dialogs/textfield.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/plugins/forms/dialogs/textfield.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/plugins/forms/dialogs/textfield.js 17 Aug 2012 14:15:44 -0000 1.1 @@ -0,0 +1,199 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ +CKEDITOR.dialog.add( 'textfield', function( editor ) +{ + var autoAttributes = + { + value : 1, + size : 1, + maxLength : 1 + }; + + var acceptedTypes = + { + text : 1, + password : 1 + }; + + return { + title : editor.lang.textfield.title, + minWidth : 350, + minHeight : 150, + onShow : function() + { + delete this.textField; + + var element = this.getParentEditor().getSelection().getSelectedElement(); + if ( element && element.getName() == "input" && + ( acceptedTypes[ element.getAttribute( 'type' ) ] || !element.getAttribute( 'type' ) ) ) + { + this.textField = element; + this.setupContent( element ); + } + }, + onOk : function() + { + var editor, + element = this.textField, + isInsertMode = !element; + + if ( isInsertMode ) + { + editor = this.getParentEditor(); + element = editor.document.createElement( 'input' ); + element.setAttribute( 'type', 'text' ); + } + + if ( isInsertMode ) + editor.insertElement( element ); + this.commitContent( { element : element } ); + }, + onLoad : function() + { + var autoSetup = function( element ) + { + var value = element.hasAttribute( this.id ) && element.getAttribute( this.id ); + this.setValue( value || '' ); + }; + + var autoCommit = function( data ) + { + var element = data.element; + var value = this.getValue(); + + if ( value ) + element.setAttribute( this.id, value ); + else + element.removeAttribute( this.id ); + }; + + this.foreach( function( contentObj ) + { + if ( autoAttributes[ contentObj.id ] ) + { + contentObj.setup = autoSetup; + contentObj.commit = autoCommit; + } + } ); + }, + contents : [ + { + id : 'info', + label : editor.lang.textfield.title, + title : editor.lang.textfield.title, + elements : [ + { + type : 'hbox', + widths : [ '50%', '50%' ], + children : + [ + { + id : '_cke_saved_name', + type : 'text', + label : editor.lang.textfield.name, + 'default' : '', + accessKey : 'N', + setup : function( element ) + { + this.setValue( + element.data( 'cke-saved-name' ) || + element.getAttribute( 'name' ) || + '' ); + }, + commit : function( data ) + { + var element = data.element; + + if ( this.getValue() ) + element.data( 'cke-saved-name', this.getValue() ); + else + { + element.data( 'cke-saved-name', false ); + element.removeAttribute( 'name' ); + } + } + }, + { + id : 'value', + type : 'text', + label : editor.lang.textfield.value, + 'default' : '', + accessKey : 'V' + } + ] + }, + { + type : 'hbox', + widths : [ '50%', '50%' ], + children : + [ + { + id : 'size', + type : 'text', + label : editor.lang.textfield.charWidth, + 'default' : '', + accessKey : 'C', + style : 'width:50px', + validate : CKEDITOR.dialog.validate.integer( editor.lang.common.validateNumberFailed ) + }, + { + id : 'maxLength', + type : 'text', + label : editor.lang.textfield.maxChars, + 'default' : '', + accessKey : 'M', + style : 'width:50px', + validate : CKEDITOR.dialog.validate.integer( editor.lang.common.validateNumberFailed ) + } + ], + onLoad : function() + { + // Repaint the style for IE7 (#6068) + if ( CKEDITOR.env.ie7Compat ) + this.getElement().setStyle( 'zoom', '100%' ); + } + }, + { + id : 'type', + type : 'select', + label : editor.lang.textfield.type, + 'default' : 'text', + accessKey : 'M', + items : + [ + [ editor.lang.textfield.typeText, 'text' ], + [ editor.lang.textfield.typePass, 'password' ] + ], + setup : function( element ) + { + this.setValue( element.getAttribute( 'type' ) ); + }, + commit : function( data ) + { + var element = data.element; + + if ( CKEDITOR.env.ie ) + { + var elementType = element.getAttribute( 'type' ); + var myType = this.getValue(); + + if ( elementType != myType ) + { + var replace = CKEDITOR.dom.element.createFromHtml( '', editor.document ); + element.copyAttributes( replace, { type : 1 } ); + replace.replace( element ); + editor.getSelection().selectElement( replace ); + data.element = replace; + } + } + else + element.setAttribute( 'type', this.getValue() ); + } + } + ] + } + ] + }; +}); Index: 3rdParty_sources/ckeditor/plugins/forms/images/hiddenfield.gif =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/plugins/forms/images/hiddenfield.gif,v diff -u Binary files differ Index: 3rdParty_sources/ckeditor/plugins/horizontalrule/plugin.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/plugins/horizontalrule/plugin.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/plugins/horizontalrule/plugin.js 17 Aug 2012 14:15:47 -0000 1.1 @@ -0,0 +1,48 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +/** + * @file Horizontal Rule plugin. + */ + +(function() +{ + var horizontalruleCmd = + { + canUndo : false, // The undo snapshot will be handled by 'insertElement'. + exec : function( editor ) + { + var hr = editor.document.createElement( 'hr' ), + range = new CKEDITOR.dom.range( editor.document ); + + editor.insertElement( hr ); + + // If there's nothing or a non-editable block followed by, establish a new paragraph + // to make sure cursor is not trapped. + range.moveToPosition( hr, CKEDITOR.POSITION_AFTER_END ); + var next = hr.getNext(); + if ( !next || next.type == CKEDITOR.NODE_ELEMENT && !next.isEditable() ) + range.fixBlock( true, editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' ); + + range.select(); + } + }; + + var pluginName = 'horizontalrule'; + + // Register a plugin named "horizontalrule". + CKEDITOR.plugins.add( pluginName, + { + init : function( editor ) + { + editor.addCommand( pluginName, horizontalruleCmd ); + editor.ui.addButton( 'HorizontalRule', + { + label : editor.lang.horizontalrule, + command : pluginName + }); + } + }); +})(); Index: 3rdParty_sources/ckeditor/plugins/htmldataprocessor/plugin.js =================================================================== RCS file: /usr/local/cvsroot/3rdParty_sources/ckeditor/plugins/htmldataprocessor/plugin.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ 3rdParty_sources/ckeditor/plugins/htmldataprocessor/plugin.js 17 Aug 2012 14:15:46 -0000 1.1 @@ -0,0 +1,596 @@ +/* +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +(function() +{ + // Regex to scan for   at the end of blocks, which are actually placeholders. + // Safari transforms the   to \xa0. (#4172) + var tailNbspRegex = /^[\t\r\n ]*(?: |\xa0)$/; + + var protectedSourceMarker = '{cke_protected}'; + + // Return the last non-space child node of the block (#4344). + function lastNoneSpaceChild( block ) + { + var lastIndex = block.children.length, + last = block.children[ lastIndex - 1 ]; + while ( last && last.type == CKEDITOR.NODE_TEXT && !CKEDITOR.tools.trim( last.value ) ) + last = block.children[ --lastIndex ]; + return last; + } + + function trimFillers( block, fromSource ) + { + // If the current node is a block, and if we're converting from source or + // we're not in IE then search for and remove any tailing BR node. + // + // Also, any   at the end of blocks are fillers, remove them as well. + // (#2886) + var children = block.children, lastChild = lastNoneSpaceChild( block ); + if ( lastChild ) + { + if ( ( fromSource || !CKEDITOR.env.ie ) && lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br' ) + children.pop(); + if ( lastChild.type == CKEDITOR.NODE_TEXT && tailNbspRegex.test( lastChild.value ) ) + children.pop(); + } + } + + function blockNeedsExtension( block, fromSource, extendEmptyBlock ) + { + if( !fromSource && ( !extendEmptyBlock || + typeof extendEmptyBlock == 'function' && ( extendEmptyBlock( block ) === false ) ) ) + return false; + + // 1. For IE version >=8, empty blocks are displayed correctly themself in wysiwiyg; + // 2. For the rest, at least table cell and list item need no filler space. + // (#6248) + if ( fromSource && CKEDITOR.env.ie && + ( document.documentMode > 7 + || block.name in CKEDITOR.dtd.tr + || block.name in CKEDITOR.dtd.$listItem ) ) + return false; + + var lastChild = lastNoneSpaceChild( block ); + + return !lastChild || lastChild && + ( lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br' + // Some of the controls in form needs extension too, + // to move cursor at the end of the form. (#4791) + || block.name == 'form' && lastChild.name == 'input' ); + } + + function getBlockExtension( isOutput, emptyBlockFiller ) + { + return function( node ) + { + trimFillers( node, !isOutput ); + + if ( blockNeedsExtension( node, !isOutput, emptyBlockFiller ) ) + { + if ( isOutput || CKEDITOR.env.ie ) + node.add( new CKEDITOR.htmlParser.text( '\xa0' ) ); + else + node.add( new CKEDITOR.htmlParser.element( 'br', {} ) ); + } + }; + } + + var dtd = CKEDITOR.dtd; + + // Define orders of table elements. + var tableOrder = [ 'caption', 'colgroup', 'col', 'thead', 'tfoot', 'tbody' ]; + + // Find out the list of block-like tags that can contain
      . + var blockLikeTags = CKEDITOR.tools.extend( {}, dtd.$block, dtd.$listItem, dtd.$tableContent ); + for ( var i in blockLikeTags ) + { + if ( ! ( 'br' in dtd[i] ) ) + delete blockLikeTags[i]; + } + // We just avoid filler in
       right now.
      +	// TODO: Support filler for 
      , line break is also occupy line height.
      +	delete blockLikeTags.pre;
      +	var defaultDataFilterRules =
      +	{
      +		elements : {},
      +		attributeNames :
      +		[
      +			// Event attributes (onXYZ) must not be directly set. They can become
      +			// active in the editing area (IE|WebKit).
      +			[ ( /^on/ ), 'data-cke-pa-on' ]
      +		]
      +	};
      +
      +	var defaultDataBlockFilterRules = { elements : {} };
      +
      +	for ( i in blockLikeTags )
      +		defaultDataBlockFilterRules.elements[ i ] = getBlockExtension();
      +
      +	var defaultHtmlFilterRules =
      +		{
      +			elementNames :
      +			[
      +				// Remove the "cke:" namespace prefix.
      +				[ ( /^cke:/ ), '' ],
      +
      +				// Ignore  tags.
      +				[ ( /^\?xml:namespace$/ ), '' ]
      +			],
      +
      +			attributeNames :
      +			[
      +				// Attributes saved for changes and protected attributes.
      +				[ ( /^data-cke-(saved|pa)-/ ), '' ],
      +
      +				// All "data-cke-" attributes are to be ignored.
      +				[ ( /^data-cke-.*/ ), '' ],
      +
      +				[ 'hidefocus', '' ]
      +			],
      +
      +			elements :
      +			{
      +				$ : function( element )
      +				{
      +					var attribs = element.attributes;
      +
      +					if ( attribs )
      +					{
      +						// Elements marked as temporary are to be ignored.
      +						if ( attribs[ 'data-cke-temp' ] )
      +							return false;
      +
      +						// Remove duplicated attributes - #3789.
      +						var attributeNames = [ 'name', 'href', 'src' ],
      +							savedAttributeName;
      +						for ( var i = 0 ; i < attributeNames.length ; i++ )
      +						{
      +							savedAttributeName = 'data-cke-saved-' + attributeNames[ i ];
      +							savedAttributeName in attribs && ( delete attribs[ attributeNames[ i ] ] );
      +						}
      +					}
      +
      +					return element;
      +				},
      +
      +				// The contents of table should be in correct order (#4809).
      +				table : function( element )
      +				{
      +					var children = element.children;
      +					children.sort( function ( node1, node2 )
      +								   {
      +									   return node1.type == CKEDITOR.NODE_ELEMENT && node2.type == node1.type ?
      +											CKEDITOR.tools.indexOf( tableOrder, node1.name )  > CKEDITOR.tools.indexOf( tableOrder, node2.name ) ? 1 : -1 : 0;
      +								   } );
      +				},
      +
      +				embed : function( element )
      +				{
      +					var parent = element.parent;
      +
      +					// If the  is child of a , copy the width
      +					// and height attributes from it.
      +					if ( parent && parent.name == 'object' )
      +					{
      +						var parentWidth = parent.attributes.width,
      +							parentHeight = parent.attributes.height;
      +						parentWidth && ( element.attributes.width = parentWidth );
      +						parentHeight && ( element.attributes.height = parentHeight );
      +					}
      +				},
      +				// Restore param elements into self-closing.
      +				param : function( param )
      +				{
      +					param.children = [];
      +					param.isEmpty = true;
      +					return param;
      +				},
      +
      +				// Remove empty link but not empty anchor.(#3829)
      +				a : function( element )
      +				{
      +					if ( !( element.children.length ||
      +							element.attributes.name ||
      +							element.attributes[ 'data-cke-saved-name' ] ) )
      +					{
      +						return false;
      +					}
      +				},
      +
      +				// Remove dummy span in webkit.
      +				span: function( element )
      +				{
      +					if ( element.attributes[ 'class' ] == 'Apple-style-span' )
      +						delete element.name;
      +				},
      +
      +				// Empty 
       in IE is reported with filler node ( ).
      +				pre : function( element ) { CKEDITOR.env.ie && trimFillers( element ); },
      +
      +				html : function( element )
      +				{
      +					delete element.attributes.contenteditable;
      +					delete element.attributes[ 'class' ];
      +				},
      +
      +				body : function( element )
      +				{
      +					delete element.attributes.spellcheck;
      +					delete element.attributes.contenteditable;
      +				},
      +
      +				style : function( element )
      +				{
      +					var child = element.children[ 0 ];
      +					child && child.value && ( child.value = CKEDITOR.tools.trim( child.value ));
      +
      +					if ( !element.attributes.type )
      +						element.attributes.type = 'text/css';
      +				},
      +
      +				title : function( element )
      +				{
      +					var titleText = element.children[ 0 ];
      +					titleText && ( titleText.value = element.attributes[ 'data-cke-title' ] || '' );
      +				}
      +			},
      +
      +			attributes :
      +			{
      +				'class' : function( value, element )
      +				{
      +					// Remove all class names starting with "cke_".
      +					return CKEDITOR.tools.ltrim( value.replace( /(?:^|\s+)cke_[^\s]*/g, '' ) ) || false;
      +				}
      +			}
      +		};
      +
      +	if ( CKEDITOR.env.ie )
      +	{
      +		// IE outputs style attribute in capital letters. We should convert
      +		// them back to lower case, while not hurting the values (#5930)
      +		defaultHtmlFilterRules.attributes.style = function( value, element )
      +		{
      +			return value.replace( /(^|;)([^\:]+)/g, function( match )
      +				{
      +					return match.toLowerCase();
      +				});
      +		};
      +	}
      +
      +	function protectReadOnly( element )
      +	{
      +		var attrs = element.attributes;
      +
      +		// We should flag that the element was locked by our code so
      +		// it'll be editable by the editor functions (#6046).
      +		if ( attrs.contenteditable != "false" )
      +			attrs[ 'data-cke-editable' ] = attrs.contenteditable ? 'true' : 1;
      +
      +		attrs.contenteditable = "false";
      +	}
      +	function unprotectReadyOnly( element )
      +	{
      +		var attrs = element.attributes;
      +		switch( attrs[ 'data-cke-editable' ] )
      +		{
      +			case 'true':	attrs.contenteditable = 'true';	break;
      +			case '1':		delete attrs.contenteditable;	break;
      +		}
      +	}
      +	// Disable form elements editing mode provided by some browers. (#5746)
      +	for ( i in { input : 1, textarea : 1 } )
      +	{
      +		defaultDataFilterRules.elements[ i ] = protectReadOnly;
      +		defaultHtmlFilterRules.elements[ i ] = unprotectReadyOnly;
      +	}
      +
      +	var protectElementRegex = /<(a|area|img|input)\b([^>]*)>/gi,
      +		protectAttributeRegex = /\b(on\w+|href|src|name)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+))/gi;
      +
      +	var protectElementsRegex = /(?:])[^>]*>[\s\S]*<\/style>)|(?:<(:?link|meta|base)[^>]*>)/gi,
      +		encodedElementsRegex = /([^<]*)<\/cke:encoded>/gi;
      +
      +	var protectElementNamesRegex = /(<\/?)((?:object|embed|param|html|body|head|title)[^>]*>)/gi,
      +		unprotectElementNamesRegex = /(<\/?)cke:((?:html|body|head|title)[^>]*>)/gi;
      +
      +	var protectSelfClosingRegex = /]*?)\/?>(?!\s*<\/cke:\1)/gi;
      +
      +	function protectAttributes( html )
      +	{
      +		return html.replace( protectElementRegex, function( element, tag, attributes )
      +		{
      +			return '<' +  tag + attributes.replace( protectAttributeRegex, function( fullAttr, attrName )
      +			{
      +				// Avoid corrupting the inline event attributes (#7243).
      +				// We should not rewrite the existed protected attributes, e.g. clipboard content from editor. (#5218)
      +				if ( !( /^on/ ).test( attrName ) && attributes.indexOf( 'data-cke-saved-' + attrName ) == -1 )
      +					return ' data-cke-saved-' + fullAttr + ' ' + fullAttr;
      +
      +				return fullAttr;
      +			}) + '>';
      +		});
      +	}
      +
      +	function protectElements( html )
      +	{
      +		return html.replace( protectElementsRegex, function( match )
      +			{
      +				return '' + encodeURIComponent( match ) + '';
      +			});
      +	}
      +
      +	function unprotectElements( html )
      +	{
      +		return html.replace( encodedElementsRegex, function( match, encoded )
      +			{
      +				return decodeURIComponent( encoded );
      +			});
      +	}
      +
      +	function protectElementsNames( html )
      +	{
      +		return html.replace( protectElementNamesRegex, '$1cke:$2');
      +	}
      +
      +	function unprotectElementNames( html )
      +	{
      +		return html.replace( unprotectElementNamesRegex, '$1$2' );
      +	}
      +
      +	function protectSelfClosingElements( html )
      +	{
      +		return html.replace( protectSelfClosingRegex, '' );
      +	}
      +
      +	function protectPreFormatted( html )
      +	{
      +		return html.replace( /(]*>)(\r\n|\n)/g, '$1$2$2' );
      +	}
      +
      +	function protectRealComments( html )
      +	{
      +		return html.replace( //g, function( match )
      +			{
      +				return '';
      +			});
      +	}
      +
      +	function unprotectRealComments( html )
      +	{
      +		return html.replace( //g, function( match, data )
      +			{
      +				return decodeURIComponent( data );
      +			});
      +	}
      +
      +	function unprotectSource( html, editor )
      +	{
      +		var store = editor._.dataStore;
      +
      +		return html.replace( //g, function( match, data )
      +			{
      +				return decodeURIComponent( data );
      +			}).replace( /\{cke_protected_(\d+)\}/g, function( match, id )
      +			{
      +				return store && store[ id ] || '';
      +			});
      +	}
      +
      +	function protectSource( data, editor )
      +	{
      +		var protectedHtml = [],
      +			protectRegexes = editor.config.protectedSource,
      +			store = editor._.dataStore || ( editor._.dataStore = { id : 1 } ),
      +			tempRegex = /<\!--\{cke_temp(comment)?\}(\d*?)-->/g;
      +
      +		var regexes =
      +			[
      +				// Script tags will also be forced to be protected, otherwise
      +				// IE will execute them.
      +				( //gi ),
      +
      +				//