1 19 20 package org.netbeans.modules.html.palette.items; 21 import javax.swing.text.BadLocationException ; 22 import javax.swing.text.JTextComponent ; 23 import org.netbeans.modules.html.palette.HTMLPaletteUtilities; 24 import org.openide.text.ActiveEditorDrop; 25 26 27 31 public class META implements ActiveEditorDrop { 32 33 public static final String TYPE_HEADERS = "HEADERS"; public static final String TYPE_ENGINES = "ENGINES"; 36 public static final String [] headers = new String [] { "Content-Type", "Content-Language", "Refresh", "Cache-Control", "Expires" }; public static final int HEADER_DEFAULT = 0; 38 public static final String [] engines = new String [] { "robots", "description", "keywords" }; public static final int ENGINE_DEFAULT = 0; 40 41 private String type = TYPE_HEADERS; 42 private int nameIndex = 0; 43 private String name = ""; 44 private String content = ""; 45 46 public META() { 47 } 48 49 public boolean handleTransfer(JTextComponent targetComponent) { 50 51 METACustomizer c = new METACustomizer(this); 52 boolean accept = c.showDialog(); 53 if (accept) { 54 String body = createBody(); 55 try { 56 HTMLPaletteUtilities.insert(body, targetComponent); 57 } catch (BadLocationException ble) { 58 accept = false; 59 } 60 } 61 62 return accept; 63 } 64 65 private String 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 strType = ""; 75 if (getType().equals(TYPE_HEADERS)) 76 strType = " http-equiv=\"" + getName() + "\""; else 78 strType = " name=\"" + getName() + "\""; 80 String strContent = " content=\"\""; if (getContent().length() > 0) 82 strContent = " content=\"" + getContent() + "\""; 84 85 String meta = "<meta" + strType + strContent + " />"; 87 return meta; 88 } 89 90 public String getType() { 91 return type; 92 } 93 94 public void setType(String 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 getName() { 107 return name; 108 } 109 110 public void setName(String name) { 111 this.name = name; 112 } 113 114 public String getContent() { 115 return content; 116 } 117 118 public void setContent(String content) { 119 this.content = content; 120 } 121 122 } 123 | Popular Tags |