KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > html > palette > items > META


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.html.palette.items;
21 import javax.swing.text.BadLocationException JavaDoc;
22 import javax.swing.text.JTextComponent JavaDoc;
23 import org.netbeans.modules.html.palette.HTMLPaletteUtilities;
24 import org.openide.text.ActiveEditorDrop;
25
26
27 /**
28  *
29  * @author Libor Kotouc
30  */

31 public class META implements ActiveEditorDrop {
32
33     public static final String JavaDoc TYPE_HEADERS = "HEADERS"; // NOI18N
34
public static final String JavaDoc TYPE_ENGINES = "ENGINES"; // NOI18N
35

36     public static final String JavaDoc[] headers = new String JavaDoc[] { "Content-Type", "Content-Language", "Refresh", "Cache-Control", "Expires" }; // NOI18N
37
public static final int HEADER_DEFAULT = 0;
38     public static final String JavaDoc[] engines = new String JavaDoc[] { "robots", "description", "keywords" }; // NOI18N
39
public static final int ENGINE_DEFAULT = 0;
40     
41     private String JavaDoc type = TYPE_HEADERS;
42     private int nameIndex = 0;
43     private String JavaDoc name = "";
44     private String JavaDoc content = "";
45     
46     public META() {
47     }
48
49     public boolean handleTransfer(JTextComponent JavaDoc targetComponent) {
50
51         METACustomizer c = new METACustomizer(this);
52         boolean accept = c.showDialog();
53         if (accept) {
54             String JavaDoc body = createBody();
55             try {
56                 HTMLPaletteUtilities.insert(body, targetComponent);
57             } catch (BadLocationException JavaDoc ble) {
58                 accept = false;
59             }
60         }
61         
62         return accept;
63     }
64
65     private String JavaDoc createBody() {
66         
67         if (getNameIndex() != -1) {
68             if (getType().equals(TYPE_HEADERS) && getNameIndex() != -1)
69                 setName(headers[getNameIndex()]);
70             else if (getType().equals(TYPE_ENGINES) && getNameIndex() != -1)
71                 setName(engines[getNameIndex()]);
72         }
73         
74         String JavaDoc strType = "";
75         if (getType().equals(TYPE_HEADERS))
76             strType = " http-equiv=\"" + getName() + "\""; // NOI18N
77
else
78             strType = " name=\"" + getName() + "\""; // NOI18N
79

80         String JavaDoc strContent = " content=\"\""; // NOI18N
81
if (getContent().length() > 0)
82             strContent = " content=\"" + getContent() + "\""; // NOI18N
83

84         
85         String JavaDoc meta = "<meta" + strType + strContent + " />"; // NOI18N
86

87         return meta;
88     }
89
90     public String JavaDoc getType() {
91         return type;
92     }
93
94     public void setType(String JavaDoc type) {
95         this.type = type;
96     }
97
98     public int getNameIndex() {
99         return nameIndex;
100     }
101
102     public void setNameIndex(int nameIndex) {
103         this.nameIndex = nameIndex;
104     }
105
106     public String JavaDoc getName() {
107         return name;
108     }
109
110     public void setName(String JavaDoc name) {
111         this.name = name;
112     }
113
114     public String JavaDoc getContent() {
115         return content;
116     }
117
118     public void setContent(String JavaDoc content) {
119         this.content = content;
120     }
121         
122 }
123
Popular Tags