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 static com.android.SdkConstants.XMLNS;
     20 import static com.android.SdkConstants.XMLNS_URI;
     21 
     22 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiAttributeNode;
     23 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
     24 
     25 
     26 /**
     27  * Describes an XMLNS attribute that is hidden.
     28  * <p/>
     29  * Such an attribute has no user interface and no corresponding {@link UiAttributeNode}.
     30  * It also has a single constant default value.
     31  * <p/>
     32  * When loading an XML, we'll ignore this attribute.
     33  * However when writing a new XML, we should always write this attribute.
     34  * <p/>
     35  * Currently this is used for the xmlns:android attribute in the manifest element.
     36  */
     37 public final class XmlnsAttributeDescriptor extends AttributeDescriptor {
     38 
     39     private String mValue;
     40 
     41     public XmlnsAttributeDescriptor(String defaultPrefix, String value) {
     42         super(defaultPrefix, XMLNS_URI, null /* info */);
     43         mValue = value;
     44     }
     45 
     46     /**
     47      * Returns the value of this specialized attribute descriptor, which is the URI associated
     48      * to the declared namespace prefix.
     49      */
     50     public String getValue() {
     51         return mValue;
     52     }
     53 
     54     /**
     55      * Returns the "xmlns" prefix that is always used by this node for its namespace URI.
     56      * This is defined by the XML specification.
     57      */
     58     public String getXmlNsPrefix() {
     59         return XMLNS;
     60     }
     61 
     62     /**
     63      * Returns the fully-qualified attribute name, namely "xmlns:xxx" where xxx is
     64      * the defaultPrefix passed in the constructor.
     65      */
     66     public String getXmlNsName() {
     67         return getXmlNsPrefix() + ":" + getXmlLocalName(); //$NON-NLS-1$
     68     }
     69 
     70     /**
     71      * @return Always returns null. {@link XmlnsAttributeDescriptor} has no user interface.
     72      */
     73     @Override
     74     public UiAttributeNode createUiNode(UiElementNode uiParent) {
     75         return null;
     76     }
     77 }
     78