📄 resourcestatement.java
字号:
}
while (node != null)
{
convertMenuItem(node, menuItemElement);
node = node.getNextSibling();
}
}
}
//------------------------------------------------------------------------------------------------
/**
* Converts a "messagetable" entry to XML.
*
* @param sourceNode The node containing the AST data to convert.
* @param resourceElement The entry to which the new nodes must be added.
*/
private void convertMessageTableEntry(AST sourceNode, Element resourceElement)
{
resourceElement.setAttribute("type", "message-table");
AST currentNode = sourceNode.getFirstChild();
if (currentNode != null)
{
String filename = currentNode.getText();
if (filename.startsWith("\""))
filename = filename.substring(1, filename.length());
resourceElement.setAttribute("file-name", filename);
}
}
//------------------------------------------------------------------------------------------------
/**
* Converts a named resource entry (dialog, user defined data etc.) to XML.
*
* @param target The XML node where to add the new content to.
*/
private void convertNamedResourceEntry(Element target)
{
Element resourceElement = new Element("named-resource");
target.addContent(resourceElement);
AST resourceNode = getAstNode();
if (resourceNode != null)
{
AST idNode = resourceNode.getFirstChild();
if (idNode != null)
{
resourceElement.setAttribute("name", idNode.getText());
AST resourceEntry = idNode.getNextSibling();
if (resourceEntry != null)
{
Integer resourceType = (Integer) resourceMap.get(resourceEntry.getText().toLowerCase());
if (resourceType == null)
reportError("Unrecognized resource type: \"" + resourceEntry.getText() + "\".");
else
{
AST entry = idNode.getNextSibling();
if (entry != null)
{
switch (resourceType.intValue())
{
case RCParserTokenTypes.LITERAL_accelerators:
{
convertAcceleratorsEntry(entry, resourceElement);
break;
}
case RCParserTokenTypes.LITERAL_bitmap:
{
convertBitmapEntry(entry, resourceElement);
break;
}
case RCParserTokenTypes.LITERAL_cursor:
{
convertCursorEntry(entry, resourceElement);
break;
}
case RCParserTokenTypes.LITERAL_dialog:
{
convertDialogEntry(entry, resourceElement);
break;
}
case RCParserTokenTypes.LITERAL_dialogex:
{
convertDialogExEntry(entry, resourceElement);
break;
}
case RCParserTokenTypes.LITERAL_font:
{
convertFontEntry(entry, resourceElement);
break;
}
case RCParserTokenTypes.LITERAL_icon:
{
convertIconEntry(entry, resourceElement);
break;
}
case RCParserTokenTypes.LITERAL_menu:
{
convertMenuEntry(entry, resourceElement);
break;
}
case RCParserTokenTypes.LITERAL_menuex:
{
convertMenuExEntry(entry, resourceElement);
break;
}
case RCParserTokenTypes.LITERAL_messagetable:
{
convertMessageTableEntry(entry, resourceElement);
break;
}
case RCParserTokenTypes.LITERAL_rcdata:
{
convertRCDataEntry(entry, resourceElement);
break;
}
case RCParserTokenTypes.LITERAL_versioninfo:
{
convertVersionInfoEntry(entry, resourceElement);
break;
}
case RCParserTokenTypes.LITERAL_textinclude:
{
convertTextincludeEntry(entry, resourceElement);
break;
}
case RCParserTokenTypes.LITERAL_designinfo:
{
convertDesignInfoEntry(entry, resourceElement);
break;
}
case RCParserTokenTypes.LITERAL_toolbar:
{
convertToolbarEntry(entry, resourceElement);
break;
}
case RCParserTokenTypes.LITERAL_dlginit:
{
convertDlgInitEntry(entry, resourceElement);
break;
}
case RCParserTokenTypes.USER_DEFINED:
{
convertUserDefinedEntry(entry, resourceElement);
break;
}
}
}
}
}
}
}
}
//------------------------------------------------------------------------------------------------
/**
* Converts a pragma code_page entry to XML.
*
* @param target The XML node where to add the new content to.
*/
private void convertPragmaEntry(Element target)
{
Element codepageElement = new Element("codepage");
target.addContent(codepageElement);
AST codepageNode = getAstNode().getFirstChild();
if (codepageNode != null)
{
AST valueNode = codepageNode.getNextSibling();
if (valueNode != null)
{
String codepageValue = valueNode.getText();
if (!codepageValue.equalsIgnoreCase("default"))
{
Object value = evaluate(codepageValue, valueNode.getLine(), valueNode.getColumn());
if (value == null)
reportError("Could not evaluate \"" + codepageValue + "\".");
else
codepageElement.setAttribute("value", ((Integer) value).toString());
}
else
codepageElement.setAttribute("value", "default");
}
}
}
//------------------------------------------------------------------------------------------------
/**
* Converts raw resource data to XML. Each entry can be either an integer or a string of data,
* separated by comma.
* Note: We are converting MSVC resource files here but Borland does uses the same rc format and
* added (at least) one special feature not supported by MS. With BRCC you can specify a
* list of hex numbers enclosed by single quotes. The parser is made to handled that and
* we simply pass the data along here.
*
* @param node The node containing the raw data.
* @param element The XML element to add the new nodes to.
*/
private void convertRawDataToXML(AST node, Element element)
{
AST currentNode = node.getFirstChild();
while (currentNode != null)
{
Element dataElement = new Element("entry");
element.addContent(dataElement);
dataElement.setAttribute("value", convertToString(currentNode.getText()));
currentNode = currentNode.getNextSibling();
}
}
//------------------------------------------------------------------------------------------------
/**
* Converts a "rcdata" entry to XML.
*
* @param sourceNode The node containing the AST data to convert.
* @param resourceElement The entry to which the new nodes must be added.
*/
private void convertRCDataEntry(AST sourceNode, Element resourceElement)
{
resourceElement.setAttribute("type", "rcdata");
AST currentNode = sourceNode.getFirstChild();
if (currentNode != null)
{
if (currentNode.getType() == RCParserTokenTypes.RESOURCE_ATTRIBUTES)
{
convertResourceAttributes(resourceElement, currentNode);
currentNode = currentNode.getNextSibling();
}
// Optional common resource info part.
if (currentNode != null)
{
while (currentNode.getType() == RCParserTokenTypes.COMMON_RESOURCE_INFO)
{
convertCommonResourceInfo(currentNode, resourceElement);
currentNode = currentNode.getNextSibling();
}
}
if (currentNode != null)
{
if (currentNode.getType() == RCParserTokenTypes.FILE_NAME)
{
String filename = currentNode.getFirstChild().getText();
if (filename.startsWith("\""))
filename = filename.substring(1, filename.length() - 1);
resourceElement.setAttribute("file-name", filename);
}
else
{
// Must be raw data, e.g. single literals (string, character, integer etc.) or
// a collection of hex numbers enclosed by single quotes.
convertRawDataToXML(currentNode, resourceElement);
}
}
}
}
//------------------------------------------------------------------------------------------------
/**
* Converts resource attributes to XML.
*
* @param element The XML element to add the new nodes to.
* @param node The AST node to convert.
*/
private void convertResourceAttributes(Element element, AST node)
{
Element attributesELement = new Element("resource-attributes");
element.setContent(attributesELement);
AST currentNode = node.getFirstChild();
while (currentNode != null)
{
Element attributeElement = new Element("attribute");
attributeElement.setAttribute("value", currentNode.getText());
attributesELement.addContent(attributeElement);
currentNode = currentNode.getNextSibling();
}
}
//------------------------------------------------------------------------------------------------
/**
* Converts a string table to XML.
*
* @param target The XML node where to add the new content to.
*/
private void convertStringTableEntry(Element target)
{
AST stringTableNode = getAstNode();
Element stringTableElement = new Element("string-table");
target.addContent(stringTableElement);
// Check if there is are (optional) resource attributes.
AST currentNode = stringTableNode.getFirstChild();
if (currentNode.getType() == RCParserTokenTypes.RESOURCE_ATTRIBUTES)
{
convertResourceAttributes(stringTableElement, currentNode);
currentNode = currentNode.getNextSibling();
}
while (currentNode != null)
{
AST symbolNode = currentNode.getFirstChild();
Element entryElement = processEntryWithEvaluation(symbolNode, "string-entry", stringTableElement);
AST valueNode = symbolNode.getNextSibling();
String value = valueNode.getText();
if (value.startsWith("\""))
value = value.substring(1, value.length() - 1);
entryElement.setAttribute("line", value);
currentNode = currentNode.getNextSibling();
}
}
//------------------------------------------------------------------------------------------------
/**
* Converts a "textinclude" entry to XML. Not sure if this info is at all relevant for
* converters and external tools, but it's there for completeness.
*
* @param sourceNode The node containing the AST data to convert.
* @param resourceElement The entry to which the new nodes must be added.
*/
private void convertTextincludeEntry(AST sourceNode, Element resourceElement)
{
resourceElement.setAttribute("type", "text-include");
AST currentNode = sourceNode.getFirstChild();
if (currentNode != null)
{
if (currentNode.getType() == RCParserTokenTypes.RESOURCE_ATTRIBUTES)
{
convertResourceAttributes(resourceElement, currentNode);
currentNode = currentNode.getNextSibling();
}
}
// Textinclude entries are just strings, simple to parse.
while (currentNode != null)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -