You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ro...@apache.org on 2008/01/02 09:27:29 UTC
svn commit: r608036 - in
/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip:
BasicCompactHeader.java BasicCompactHeaderMapper.java
BasicSipLineParser.java BufferedCompactHeader.java CompactHeader.java
CompactHeaderMapper.java
Author: rolandw
Date: Wed Jan 2 00:27:27 2008
New Revision: 608036
URL: http://svn.apache.org/viewvc?rev=608036&view=rev
Log:
more SIP contrib code
Added:
httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BasicCompactHeader.java (with props)
httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BasicCompactHeaderMapper.java (with props)
httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BasicSipLineParser.java (with props)
httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BufferedCompactHeader.java (with props)
httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/CompactHeader.java (with props)
httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/CompactHeaderMapper.java (with props)
Added: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BasicCompactHeader.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BasicCompactHeader.java?rev=608036&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BasicCompactHeader.java (added)
+++ httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BasicCompactHeader.java Wed Jan 2 00:27:27 2008
@@ -0,0 +1,118 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.contrib.sip;
+
+import org.apache.http.message.BasicHeader;
+
+
+/**
+ * Represents a SIP (or HTTP) header field with optional compact name.
+ *
+ * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
+ *
+ * @version $Revision$
+ */
+public class BasicCompactHeader extends BasicHeader
+ implements CompactHeader {
+
+ /** The compact name, if there is one. */
+ private final String compact;
+
+
+ /**
+ * Constructor with names and value.
+ *
+ * @param fullname the full header name
+ * @param compactname the compact header name, or <code>null</code>
+ * @param value the header value
+ */
+ public BasicCompactHeader(final String fullname,
+ final String compactname,
+ final String value) {
+ super(fullname, value);
+
+ if ((compactname != null) &&
+ (compactname.length() >= fullname.length())) {
+ throw new IllegalArgumentException
+ ("Compact name must be shorter than full name. " +
+ compactname + " -> " + fullname);
+ }
+
+ this.compact = compactname;
+ }
+
+
+ // non-javadoc, see interface CompactHeader
+ public String getCompactName() {
+ return this.compact;
+ }
+
+
+ /**
+ * Creates a compact header with automatic lookup.
+ *
+ * @param name the header name, either full or compact
+ * @param value the header value
+ * @param mapper the header name mapper, or <code>null</code> for the
+ * {@link BasicCompactHeaderMapper#DEFAULT default}
+ */
+ public static
+ BasicCompactHeader newHeader(final String name, final String value,
+ CompactHeaderMapper mapper) {
+ if (name == null) {
+ throw new IllegalArgumentException
+ ("The name must not be null.");
+ }
+ // value will be checked by constructor later
+
+ if (mapper == null)
+ mapper = BasicCompactHeaderMapper.DEFAULT;
+
+ final String altname = mapper.getAlternateName(name);
+
+ String fname = name;
+ String cname = altname;
+
+ if ((altname != null) && (name.length() < altname.length())) {
+ // we were called with the compact name
+ fname = altname;
+ cname = name;
+ }
+
+ return new BasicCompactHeader(fname, cname, value);
+ }
+
+
+ // we might want a toString method that includes the short name, if defined
+
+ // default cloning implementation is fine
+}
Propchange: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BasicCompactHeader.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BasicCompactHeader.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BasicCompactHeader.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BasicCompactHeaderMapper.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BasicCompactHeaderMapper.java?rev=608036&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BasicCompactHeaderMapper.java (added)
+++ httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BasicCompactHeaderMapper.java Wed Jan 2 00:27:27 2008
@@ -0,0 +1,214 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.contrib.sip;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Collections;
+
+
+
+/**
+ * Basic implementation of a {@link CompactHeaderMapper}.
+ * Header names are assumed to be case insensitive.
+ *
+ * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
+ *
+ * @version $Revision$
+ */
+public class BasicCompactHeaderMapper implements CompactHeaderMapper {
+
+ /**
+ * The map from compact names to full names.
+ * Keys are converted to lower case, values may be mixed case.
+ */
+ protected Map<String,String> mapCompactToFull;
+
+ /**
+ * The map from full names to compact names.
+ * Keys are converted to lower case, values may be mixed case.
+ */
+ protected Map<String,String> mapFullToCompact;
+
+
+ /**
+ * The default mapper.
+ * This mapper is initialized with the compact header names defined at
+ * <a href="http://www.iana.org/assignments/sip-parameters">
+ * http://www.iana.org/assignments/sip-parameters
+ * </a>
+ * on 2008-01-02.
+ */
+ // see below for static initialization
+ public final static CompactHeaderMapper DEFAULT;
+
+
+ /**
+ * Creates a new header mapper with an empty mapping.
+ */
+ public BasicCompactHeaderMapper() {
+ createMaps();
+ }
+
+
+ /**
+ * Initializes the two maps.
+ * The default implementation here creates an empty hash map for
+ * each attribute that is <code>null</code>.
+ * Derived implementations may choose to instantiate other
+ * map implementations, or to populate the maps by default.
+ * In the latter case, it is the responsibility of the dervied class
+ * to guarantee consistent mappings in both directions.
+ */
+ protected void createMaps() {
+ if (mapCompactToFull == null) {
+ mapCompactToFull = new HashMap<String,String>();
+ }
+ if (mapFullToCompact == null) {
+ mapFullToCompact = new HashMap<String,String>();
+ }
+ }
+
+
+ /**
+ * Adds a header name mapping.
+ *
+ * @param compact the compact name of the header
+ * @param full the full name of the header
+ */
+ public void addMapping(final String compact, final String full) {
+ if (compact == null) {
+ throw new IllegalArgumentException
+ ("The compact name must not be null.");
+ }
+ if (full == null) {
+ throw new IllegalArgumentException
+ ("The full name must not be null.");
+ }
+ if (compact.length() >= full.length()) {
+ throw new IllegalArgumentException
+ ("The compact name must be shorter than the full name. " +
+ compact + " -> " + full);
+ }
+
+ mapCompactToFull.put(compact.toLowerCase(), full);
+ mapFullToCompact.put(full.toLowerCase(), compact);
+ }
+
+
+ /**
+ * Switches this mapper to read-only mode.
+ * Subsequent invocations of {@link #addMapping addMapping}
+ * will trigger an exception.
+ * <br/>
+ * The implementation here should be called only once.
+ * It replaces the internal maps with unmodifiable ones.
+ */
+ protected void makeReadOnly() {
+ mapCompactToFull = Collections.unmodifiableMap(mapCompactToFull);
+ mapFullToCompact = Collections.unmodifiableMap(mapFullToCompact);
+ }
+
+
+ // non-javadoc, see interface CompactHeaderMapper
+ public String getCompactName(final String fullname) {
+ if (fullname == null) {
+ throw new IllegalArgumentException
+ ("The full name must not be null.");
+ }
+ return mapFullToCompact.get(fullname.toLowerCase());
+ }
+
+
+ // non-javadoc, see interface CompactHeaderMapper
+ public String getFullName(final String compactname) {
+ if (compactname == null) {
+ throw new IllegalArgumentException
+ ("The compact name must not be null.");
+ }
+ return mapCompactToFull.get(compactname.toLowerCase());
+ }
+
+
+ // non-javadoc, see interface CompactHeaderMapper
+ public String getAlternateName(final String name) {
+ if (name == null) {
+ throw new IllegalArgumentException
+ ("The name must not be null.");
+ }
+
+ final String namelc = name.toLowerCase();
+ String result = null;
+
+ // to minimize lookups, use a heuristic to determine the direction
+ boolean iscompact = name.length() < 2;
+ if (iscompact) {
+ result = mapCompactToFull.get(namelc);
+ }
+ if (result == null) {
+ result = mapFullToCompact.get(namelc);
+ }
+ if ((result == null) && !iscompact) {
+ result = mapCompactToFull.get(namelc);
+ }
+
+ return result;
+ }
+
+
+ // initializes the default mapper and switches it to read-only mode
+ static {
+ BasicCompactHeaderMapper chm = new BasicCompactHeaderMapper();
+ chm.addMapping("a", "Accept-Contact");
+ chm.addMapping("u", "Allow-Events");
+ chm.addMapping("i", "Call-ID");
+ chm.addMapping("m", "Contact");
+ chm.addMapping("e", "Content-Encoding");
+ chm.addMapping("l", "Content-Length");
+ chm.addMapping("c", "Content-Type");
+ chm.addMapping("o", "Event");
+ chm.addMapping("f", "From");
+ chm.addMapping("y", "Identity");
+ chm.addMapping("n", "Identity-Info");
+ chm.addMapping("r", "Refer-To");
+ chm.addMapping("b", "Referred-By");
+ chm.addMapping("j", "Reject-Contact");
+ chm.addMapping("d", "Request-Disposition");
+ chm.addMapping("x", "Session-Expires");
+ chm.addMapping("s", "Subject");
+ chm.addMapping("k", "Supported");
+ chm.addMapping("t", "To");
+ chm.addMapping("v", "Via");
+ chm.makeReadOnly();
+ DEFAULT = chm;
+ }
+}
Propchange: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BasicCompactHeaderMapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BasicCompactHeaderMapper.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BasicCompactHeaderMapper.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BasicSipLineParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BasicSipLineParser.java?rev=608036&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BasicSipLineParser.java (added)
+++ httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BasicSipLineParser.java Wed Jan 2 00:27:27 2008
@@ -0,0 +1,82 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.contrib.sip;
+
+import org.apache.http.Header;
+import org.apache.http.ParseException;
+import org.apache.http.util.CharArrayBuffer;
+import org.apache.http.message.BasicLineParser;
+
+
+/**
+ * Basic parser for lines in the head section of an SIP message.
+ *
+ * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
+ *
+ * @version $Revision$
+ */
+public class BasicSipLineParser extends BasicLineParser {
+
+ /** The header name mapper to use, never <code>null</code>. */
+ protected final CompactHeaderMapper mapper;
+
+
+ /**
+ * A default instance of this class, for use as default or fallback.
+ */
+ public final static
+ BasicSipLineParser DEFAULT = new BasicSipLineParser(null);
+
+
+ /**
+ * Creates a new line parser for SIP protocol.
+ *
+ * @param mapper the header name mapper, or <code>null</code> for the
+ * {@link BasicCompactHeaderMapper#DEFAULT default}
+ */
+ public BasicSipLineParser(CompactHeaderMapper mapper) {
+ super(SipVersion.SIP_2_0);
+ this.mapper = (mapper != null) ?
+ mapper : BasicCompactHeaderMapper.DEFAULT;
+ }
+
+
+ // non-javadoc, see interface LineParser
+ public Header parseHeader(CharArrayBuffer buffer)
+ throws ParseException {
+
+ // the actual parser code is in the constructor of BufferedHeader
+ return new BufferedCompactHeader(buffer, mapper);
+ }
+
+}
+
Propchange: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BasicSipLineParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BasicSipLineParser.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BasicSipLineParser.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BufferedCompactHeader.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BufferedCompactHeader.java?rev=608036&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BufferedCompactHeader.java (added)
+++ httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BufferedCompactHeader.java Wed Jan 2 00:27:27 2008
@@ -0,0 +1,171 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.contrib.sip;
+
+import org.apache.http.FormattedHeader;
+import org.apache.http.HeaderElement;
+import org.apache.http.ParseException;
+import org.apache.http.util.CharArrayBuffer;
+import org.apache.http.message.ParserCursor;
+import org.apache.http.message.BasicHeaderValueParser;
+
+
+/**
+ * Represents a SIP (or HTTP) header field parsed 'on demand'.
+ * The name of the header will be parsed and mapped immediately,
+ * the value only when accessed
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
+ *
+ * @version $Revision$
+ */
+public class BufferedCompactHeader
+ implements CompactHeader, FormattedHeader, Cloneable {
+
+ /** The full header name. */
+ private final String fullName;
+
+ /** The compact header name, if there is one. */
+ private final String compactName;
+
+ /**
+ * The buffer containing the entire header line.
+ */
+ private final CharArrayBuffer buffer;
+
+ /**
+ * The beginning of the header value in the buffer
+ */
+ private final int valuePos;
+
+
+ /**
+ * Creates a new header from a buffer.
+ * The name of the header will be parsed and mapped immediately,
+ * the value only if it is accessed.
+ *
+ * @param buffer the buffer containing the header to represent
+ * @param mapper the header name mapper, or <code>null</code> for the
+ * {@link BasicCompactHeaderMapper#DEFAULT default}
+ *
+ * @throws ParseException in case of a parse error
+ */
+ public BufferedCompactHeader(final CharArrayBuffer buffer,
+ CompactHeaderMapper mapper)
+ throws ParseException {
+
+ super();
+ if (buffer == null) {
+ throw new IllegalArgumentException
+ ("Char array buffer may not be null");
+ }
+
+ final int colon = buffer.indexOf(':');
+ if (colon == -1) {
+ throw new ParseException
+ ("Missing colon after header name.\n" + buffer.toString());
+ }
+ final String name = buffer.substringTrimmed(0, colon);
+ if (name.length() == 0) {
+ throw new ParseException
+ ("Missing header name.\n" + buffer.toString());
+ }
+
+ if (mapper == null)
+ mapper = BasicCompactHeaderMapper.DEFAULT;
+ final String altname = mapper.getAlternateName(name);
+
+ String fname = name;
+ String cname = altname;
+
+ if ((altname != null) && (name.length() < altname.length())) {
+ // the header uses the compact name
+ fname = altname;
+ cname = name;
+ }
+
+ this.fullName = fname;
+ this.compactName = cname;
+ this.buffer = buffer;
+ this.valuePos = colon + 1;
+ }
+
+
+ // non-javadoc, see interface Header
+ public String getName() {
+ return this.fullName;
+ }
+
+
+ // non-javadoc, see interface CompactHeader
+ public String getCompactName() {
+ return this.compactName;
+ }
+
+ // non-javadoc, see interface Header
+ public String getValue() {
+ return this.buffer.substringTrimmed(this.valuePos,
+ this.buffer.length());
+ }
+
+ // non-javadoc, see interface Header
+ public HeaderElement[] getElements() throws ParseException {
+ ParserCursor cursor = new ParserCursor(0, this.buffer.length());
+ cursor.updatePos(this.valuePos);
+ return BasicHeaderValueParser.DEFAULT
+ .parseElements(this.buffer, cursor);
+ }
+
+ // non-javadoc, see interface BufferedHeader
+ public int getValuePos() {
+ return this.valuePos;
+ }
+
+ // non-javadoc, see interface BufferedHeader
+ public CharArrayBuffer getBuffer() {
+ return this.buffer;
+ }
+
+ public String toString() {
+ return this.buffer.toString();
+ }
+
+ public Object clone() throws CloneNotSupportedException {
+ // buffer is considered immutable
+ // no need to make a copy of it
+ return super.clone();
+ }
+
+}
+
+
Propchange: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BufferedCompactHeader.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BufferedCompactHeader.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/BufferedCompactHeader.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/CompactHeader.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/CompactHeader.java?rev=608036&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/CompactHeader.java (added)
+++ httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/CompactHeader.java Wed Jan 2 00:27:27 2008
@@ -0,0 +1,66 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.contrib.sip;
+
+
+import org.apache.http.Header;
+
+
+/**
+ * Represents an SIP (or HTTP) header field with an optional compact name.
+ * RFC 3261 (SIP/2.0), section 7.3.3 specifies that some header field
+ * names have an abbreviated form which is equivalent to the full name.
+ * All compact header names defined for SIP are registered at
+ * <a href="http://www.iana.org/assignments/sip-parameters">
+ * http://www.iana.org/assignments/sip-parameters
+ * </a>.
+ * <br/>
+ * While all compact names defined so far are single-character names,
+ * RFC 3261 does not mandate that. This interface therefore allows for
+ * strings as the compact name.
+ *
+ * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
+ *
+ * @version $Revision$
+ */
+public interface CompactHeader extends Header {
+
+ /**
+ * Obtains the name of this header in compact form, if there is one.
+ *
+ * @return the compact name of this header, or
+ * <code>null</code> if there is none
+ */
+ String getCompactName()
+ ;
+
+}
Propchange: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/CompactHeader.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/CompactHeader.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/CompactHeader.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/CompactHeaderMapper.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/CompactHeaderMapper.java?rev=608036&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/CompactHeaderMapper.java (added)
+++ httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/CompactHeaderMapper.java Wed Jan 2 00:27:27 2008
@@ -0,0 +1,101 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.contrib.sip;
+
+
+
+/**
+ * A mapper between full and compact header names.
+ * RFC 3261 (SIP/2.0), section 7.3.3 specifies that some header field
+ * names have an abbreviated form which is equivalent to the full name.
+ * All compact header names defined for SIP are registered at
+ * <a href="http://www.iana.org/assignments/sip-parameters">
+ * http://www.iana.org/assignments/sip-parameters
+ * </a>.
+ * <br/>
+ * While all compact names defined so far are single-character names,
+ * RFC 3261 does not mandate that. This interface therefore allows for
+ * strings as the compact name.
+ *
+ * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
+ *
+ * @version $Revision$
+ */
+public interface CompactHeaderMapper {
+
+ /**
+ * Obtains the compact name for the given full name.
+ *
+ * @param fullname the header name for which to look up the compact form
+ *
+ * @return the compact form of the argument header name, or
+ * <code>null</code> if there is none
+ */
+ String getCompactName(String fullname)
+ ;
+
+
+ /**
+ * Obtains the full name for the given compact name.
+ *
+ * @param compactname the compact name for which to look up the full name
+ *
+ * @return the full name of the argument compact header name, or
+ * <code>null</code> if there is none
+ */
+ String getFullName(String compactname)
+ ;
+
+
+ /**
+ * Obtains the alternate name for the given header name.
+ * This performs a lookup in both directions, if necessary.
+ * <br/>
+ * If the returned name is shorter than the argument name,
+ * the argument was a full header name and the result is
+ * the compact name.
+ * If the returned name is longer than the argument name,
+ * the argument was a compact header name and the result
+ * is the full name.
+ * If the returned name has the same length as the argument name,
+ * somebody didn't understand the concept of a <i>compact form</i>
+ * when defining the mapping. You should expect malfunctioning
+ * applications in this case.
+ *
+ * @param name the header name to map, either a full or compact name
+ *
+ * @return the alternate header name, or
+ * <code>null</code> if there is none
+ */
+ String getAlternateName(String name)
+ ;
+}
Propchange: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/CompactHeaderMapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/CompactHeaderMapper.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/sip/CompactHeaderMapper.java
------------------------------------------------------------------------------
svn:mime-type = text/plain