/* * Copyright (c) 2004-2005 Hans Kratz. * Geert Bevin . * All Rights Reserved. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ import com.omnicore.cle.abstraction.EditorIndenterAbstraction; import com.omnicore.cle.abstraction.EditorModeAbstraction; import com.omnicore.cle.abstraction.HighlighterAbstraction; import com.omnicore.cle.abstraction.ParenMatcherAbstraction; import com.omnicore.cle.api.codetemplates.CodeTemplate; import com.omnicore.cle.api.parenmatcher.HighlightingAwareParenMatcher; import com.omnicore.guibuilder.abstraction.GUIBuilderBindingAbstraction; import java.awt.Image; import java.awt.Toolkit; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import javax.swing.Icon; import javax.swing.ImageIcon; public class RIFEXmlEditorMode implements EditorModeAbstraction { private final static CodeTemplate[] CODE_TEMPLATES; static { CODE_TEMPLATES = new CodeTemplate[36]; CodeTemplate template; template = new CodeTemplate(); template.abbrev = "v"; template.description = "Short invisible template value"; template.text = ""; CODE_TEMPLATES[0] = template; template = new CodeTemplate(); template.abbrev = "vl"; template.description = "Long invisible template value"; template.text = ""; CODE_TEMPLATES[1] = template; template = new CodeTemplate(); template.abbrev = "vc"; template.description = "Short compact template value"; template.text = "[!V '|'/]"; CODE_TEMPLATES[2] = template; template = new CodeTemplate(); template.abbrev = "vcl"; template.description = "Long compact template value"; template.text = "[!V '|'][!/V]"; CODE_TEMPLATES[3] = template; template = new CodeTemplate(); template.abbrev = "i"; template.description = "Invisible template include"; template.text = ""; CODE_TEMPLATES[4] = template; template = new CodeTemplate(); template.abbrev = "ic"; template.description = "Compact template include"; template.text = ""; CODE_TEMPLATES[5] = template; template = new CodeTemplate(); template.abbrev = "b"; template.description = "Invisible template block"; template.text = ""; CODE_TEMPLATES[6] = template; template = new CodeTemplate(); template.abbrev = "bc"; template.description = "Compact template block"; template.text = "[!B '|'][!/B]"; CODE_TEMPLATES[7] = template; template = new CodeTemplate(); template.abbrev = "bv"; template.description = "Invisible template blockvalue"; template.text = ""; CODE_TEMPLATES[8] = template; template = new CodeTemplate(); template.abbrev = "bvc"; template.description = "Compact template blockvalue"; template.text = "[!BV '|'][!/BV]"; CODE_TEMPLATES[9] = template; template = new CodeTemplate(); template.abbrev = "e"; template.description = "Short invisible template embedded element value"; template.text = ""; CODE_TEMPLATES[10] = template; template = new CodeTemplate(); template.abbrev = "el"; template.description = "Long invisible template embedded element value"; template.text = ""; CODE_TEMPLATES[11] = template; template = new CodeTemplate(); template.abbrev = "ec"; template.description = "Short compact template embedded element value"; template.text = "[!V 'ELEMENT:|'/]"; CODE_TEMPLATES[12] = template; template = new CodeTemplate(); template.abbrev = "ecl"; template.description = "Long compact template embedded element value"; template.text = "[!V 'ELEMENT:|'][!/V]"; CODE_TEMPLATES[13] = template; template = new CodeTemplate(); template.abbrev = "l"; template.description = "Short invisible template localization value"; template.text = ""; CODE_TEMPLATES[14] = template; template = new CodeTemplate(); template.abbrev = "ll"; template.description = "Long invisible template localization value"; template.text = ""; CODE_TEMPLATES[15] = template; template = new CodeTemplate(); template.abbrev = "lc"; template.description = "Short compact template localization value"; template.text = "[!V 'L10N:|'/]"; CODE_TEMPLATES[16] = template; template = new CodeTemplate(); template.abbrev = "lcl"; template.description = "Long compact template localization value"; template.text = "[!V 'L10N:|'][!/V]"; CODE_TEMPLATES[17] = template; template = new CodeTemplate(); template.abbrev = "fsubm"; template.description = "XHTML form submission"; template.text = "
\n"+ "\t|\n"+ "
"; CODE_TEMPLATES[18] = template; template = new CodeTemplate(); template.abbrev = "finput"; template.description = "Short XHTML form input field"; template.text = ""; CODE_TEMPLATES[19] = template; template = new CodeTemplate(); template.abbrev = "finputl"; template.description = "Long XHTML form input field"; template.text = "|"; CODE_TEMPLATES[20] = template; template = new CodeTemplate(); template.abbrev = "fsecret"; template.description = "Short XHTML form secret field"; template.text = ""; CODE_TEMPLATES[21] = template; template = new CodeTemplate(); template.abbrev = "fsecretl"; template.description = "Long XHTML form secret field"; template.text = "|"; CODE_TEMPLATES[22] = template; template = new CodeTemplate(); template.abbrev = "ftextarea"; template.description = "Short XHTML form textarea field"; template.text = ""; CODE_TEMPLATES[23] = template; template = new CodeTemplate(); template.abbrev = "ftextareal"; template.description = "Long XHTML form textarea field"; template.text = "|"; CODE_TEMPLATES[24] = template; template = new CodeTemplate(); template.abbrev = "fradio"; template.description = "Short XHTML form radio button"; template.text = ""; CODE_TEMPLATES[25] = template; template = new CodeTemplate(); template.abbrev = "fradiol"; template.description = "Long XHTML form radio button"; template.text = "|"; CODE_TEMPLATES[26] = template; template = new CodeTemplate(); template.abbrev = "fcheckbox"; template.description = "Short XHTML form checkbox button"; template.text = ""; CODE_TEMPLATES[27] = template; template = new CodeTemplate(); template.abbrev = "fcheckboxl"; template.description = "Long XHTML form checkbox button"; template.text = "|"; CODE_TEMPLATES[28] = template; template = new CodeTemplate(); template.abbrev = "fselect"; template.description = "Short XHTML form select field"; template.text = ""; CODE_TEMPLATES[29] = template; template = new CodeTemplate(); template.abbrev = "fselectl"; template.description = "Long XHTML form select field"; template.text = "|"; CODE_TEMPLATES[30] = template; template = new CodeTemplate(); template.abbrev = "fhidden"; template.description = "Short XHTML form hidden field"; template.text = ""; CODE_TEMPLATES[31] = template; template = new CodeTemplate(); template.abbrev = "fhiddenl"; template.description = "Long XHTML form hidden field"; template.text = "|"; CODE_TEMPLATES[32] = template; template = new CodeTemplate(); template.abbrev = "ffinput"; template.description = "XHTML input form field"; template.text = "
\n"+ "\t
\n"+ "\t
\n"+ "\t\t
\n"+ "\t\t\t\n"+ "\t\t\tid=\"$1$\"\n"+ "\t\t
\n"+ "\t
\n"+ "
"; CODE_TEMPLATES[33] = template; template = new CodeTemplate(); template.abbrev = "fftextarea"; template.description = "XHTML textarea form field"; template.text = "
\n"+ "\t
\n"+ "\t
\n"+ "\t\t
\n"+ "\t\t\t\n"+ "\t\t\tid=\"$1$\"\n"+ "\t\t
\n"+ "\t
\n"+ "
"; CODE_TEMPLATES[34] = template; template = new CodeTemplate(); template.abbrev = "ff"; template.description = "XHTML form field"; template.text = "
\n"+ "\t
\n"+ "\t
\n"+ "\t\t
\n"+ "\t\t\t\n"+ "\t\t\t|\n"+ "\t\t
\n"+ "\t
\n"+ "
"; CODE_TEMPLATES[35] = template; } public String getName() { return "RIFE XML"; } public Icon getFileIcon(boolean errors) { return loadIcon("rifexmldocument.png"); } private Icon loadIcon(String name) { try { InputStream inStream = getClass().getResourceAsStream(name); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; int count; while ((count = inStream.read(buffer)) != -1) outStream.write(buffer, 0, count); outStream.close(); Image img = Toolkit.getDefaultToolkit().createImage(outStream.toByteArray()); return new ImageIcon(img); } catch (IOException e) {} return null; } public String[] getDefaultFilePatterns() { return new String[] { "*.xml", "*.html", "*.xhtml", "*.htm", }; } public HighlighterAbstraction createHighlighter() { return new RIFEXmlHighlighterMetadata(); } public EditorIndenterAbstraction getEditorIndenter() { return null; } public ParenMatcherAbstraction createEditorParenMatcher() { return new HighlightingAwareParenMatcher ( "<", ">", new int[] {} ); } public CodeTemplate[] getDefaultCodeTemplates() { return CODE_TEMPLATES; } public GUIBuilderBindingAbstraction getGUIDesignerBinding() { return null; } public String getLanguageFormattedString(String string) { return string; } public boolean supportsChecking() { return false; } public boolean supportsCheckingByDefault() { return false; } }