Home | History | Annotate | Download | only in descriptors
      1 /*
      2  * Copyright (C) 2007 The Android Open Source Project
      3  *
      4  * Licensed under the Eclipse Public License, Version 1.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.eclipse.org/org/documents/epl-v10.php
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.ide.eclipse.adt.internal.editors.descriptors;
     18 
     19 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiAttributeNode;
     20 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
     21 
     22 
     23 /**
     24  * Describes an XMLNS attribute that is hidden.
     25  * <p/>
     26  * Such an attribute has no user interface and no corresponding {@link UiAttributeNode}.
     27  * It also has a single constant default value.
     28  * <p/>
     29  * When loading an XML, we'll ignore this attribute.
     30  * However when writing a new XML, we should always write this attribute.
     31  * <p/>
     32  * Currently this is used for the xmlns:android attribute in the manifest element.
     33  */
     34 public final class XmlnsAttributeDescriptor extends AttributeDescriptor {
     35 
     36     /**
     37      * URI of the reserved "xmlns"  prefix, as described in
     38      * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/namespaces-algorithms.html#normalizeDocumentAlgo
     39      */
     40     public final static String XMLNS_URI = "http://www.w3.org/2000/xmlns/"; //$NON-NLS-1$
     41 
     42     /** The "xmlns" attribute name */
     43     public static final String XMLNS = "xmlns"; //$NON-NLS-1$
     44 
     45     /** The "xmlns:" attribute prefix used for namespace declarations */
     46     public static final String XMLNS_COLON = "xmlns:"; //$NON-NLS-1$
     47 
     48     private String mValue;
     49 
     50 
     51     public XmlnsAttributeDescriptor(String defaultPrefix, String value) {
     52         super(defaultPrefix, XMLNS_URI, null /* info */);
     53         mValue = value;
     54     }
     55 
     56     /**
     57      * Returns the value of this specialized attribute descriptor, which is the URI associated
     58      * to the declared namespace prefix.
     59      */
     60     public String getValue() {
     61         return mValue;
     62     }
     63 
     64     /**
     65      * Returns the "xmlns" prefix that is always used by this node for its namespace URI.
     66      * This is defined by the XML specification.
     67      */
     68     public String getXmlNsPrefix() {
     69         return XmlnsAttributeDescriptor.XMLNS;
     70     }
     71 
     72     /**
     73      * Returns the fully-qualified attribute name, namely "xmlns:xxx" where xxx is
     74      * the defaultPrefix passed in the constructor.
     75      */
     76     public String getXmlNsName() {
     77         return getXmlNsPrefix() + ":" + getXmlLocalName(); //$NON-NLS-1$
     78     }
     79 
     80     /**
     81      * @return Always returns null. {@link XmlnsAttributeDescriptor} has no user interface.
     82      */
     83     @Override
     84     public UiAttributeNode createUiNode(UiElementNode uiParent) {
     85         return null;
     86     }
     87 }
     88