use of com.webobjects.foundation.NSMutableDictionary in project wonder-slim by undur.
the class WOHelperFunctionParser method processDeclaration.
protected void processDeclaration(WODeclaration declaration) {
NSMutableDictionary associations = (NSMutableDictionary) declaration.associations();
Enumeration bindingNameEnum = associations.keyEnumerator();
while (bindingNameEnum.hasMoreElements()) {
String bindingName = (String) bindingNameEnum.nextElement();
WOAssociation association = (WOAssociation) associations.valueForKey(bindingName);
WOAssociation helperAssociation = parserHelperAssociation(association);
if (helperAssociation != association) {
associations.setObjectForKey(helperAssociation, bindingName);
}
}
// This will replace constant associations with ognl associations
// when needed.
WOOgnl.factory().convertOgnlConstantAssociations(associations);
}
use of com.webobjects.foundation.NSMutableDictionary in project wonder-slim by undur.
the class WOHelperFunctionDeclarationParser method parseDeclarationsWithoutComments.
private NSMutableDictionary parseDeclarationsWithoutComments(String declarationWithoutComment) throws WOHelperFunctionDeclarationFormatException {
NSMutableDictionary declarations = new NSMutableDictionary();
NSMutableDictionary rawDeclarations = _rawDeclarationsWithoutComment(declarationWithoutComment);
String tagName;
WODeclaration declaration;
Enumeration rawDeclarationHeaderEnum = rawDeclarations.keyEnumerator();
while (rawDeclarationHeaderEnum.hasMoreElements()) {
String declarationHeader = (String) rawDeclarationHeaderEnum.nextElement();
String declarationBody = (String) rawDeclarations.objectForKey(declarationHeader);
int colonIndex = declarationHeader.indexOf(':');
if (colonIndex < 0) {
throw new WOHelperFunctionDeclarationFormatException("<WOHelperFunctionDeclarationParser> Missing ':' for declaration:\n" + declarationHeader + " " + declarationBody);
}
tagName = declarationHeader.substring(0, colonIndex).trim();
if (tagName.length() == 0) {
throw new WOHelperFunctionDeclarationFormatException("<WOHelperFunctionDeclarationParser> Missing tag name for declaration:\n" + declarationHeader + " " + declarationBody);
}
if (declarations.objectForKey(tagName) != null) {
throw new WOHelperFunctionDeclarationFormatException("<WOHelperFunctionDeclarationParser> Duplicate tag name '" + tagName + "' in declaration:\n" + declarationBody);
}
String type = declarationHeader.substring(colonIndex + 1).trim();
if (type.length() == 0) {
throw new WOHelperFunctionDeclarationFormatException("<WOHelperFunctionDeclarationParser> Missing element name for declaration:\n" + declarationHeader + " " + declarationBody);
}
NSMutableDictionary associations = _associationsForDictionaryString(declarationHeader, declarationBody);
declaration = WOHelperFunctionParser.createDeclaration(tagName, type, associations);
declarations.setObjectForKey(declaration, tagName);
}
return declarations;
}
use of com.webobjects.foundation.NSMutableDictionary in project wonder-slim by undur.
the class WOHelperFunctionDeclarationParser method _rawDeclarationsWithoutComment.
private NSMutableDictionary _rawDeclarationsWithoutComment(String declarationStr) {
NSMutableDictionary declarations = new NSMutableDictionary();
StringBuilder declarationWithoutCommentBuffer = new StringBuilder(100);
StringTokenizer tokenizer = new StringTokenizer(declarationStr, "{", true);
try {
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken("{");
if (token.equals("{")) {
token = tokenizer.nextToken("}");
if (token.equals("}")) {
token = "";
} else {
tokenizer.nextToken();
}
String declarationWithoutComment = declarationWithoutCommentBuffer.toString();
if (declarationWithoutComment.startsWith(";")) {
declarationWithoutComment = declarationWithoutComment.substring(1);
}
declarations.setObjectForKey("{" + token + "}", declarationWithoutComment.trim());
declarationWithoutCommentBuffer.setLength(0);
} else {
declarationWithoutCommentBuffer.append(token);
}
}
} catch (NoSuchElementException e) {
log.debug("Failed to parse.", e);
}
return declarations;
}
use of com.webobjects.foundation.NSMutableDictionary in project wonder-slim by undur.
the class WOHelperFunctionHTMLParser method parseHTML.
public void parseHTML() throws WOHelperFunctionHTMLFormatException, WOHelperFunctionDeclarationFormatException, ClassNotFoundException {
_stackDict = new NSMutableDictionary();
StringTokenizer templateTokenizer = new StringTokenizer(_unparsedTemplate, "<");
boolean flag = true;
int parserState = STATE_OUTSIDE;
String token;
if (_unparsedTemplate.startsWith("<") || !templateTokenizer.hasMoreTokens()) {
token = null;
} else {
token = templateTokenizer.nextToken("<");
}
try {
do {
if (!templateTokenizer.hasMoreTokens()) {
break;
}
switch(parserState) {
case STATE_OUTSIDE:
if (token != null) {
if (token.startsWith(">")) {
token = token.substring(1);
}
_contentText.append(token);
}
token = templateTokenizer.nextToken(">");
int tagIndex;
// parses non wo: tags for dynamic bindings
if (_parseStandardTags) {
token = checkToken(token);
}
String tagLowerCase = token.toLowerCase();
if (tagLowerCase.startsWith(WEBOBJECT_START_TAG) || tagLowerCase.startsWith(WO_COLON_START_TAG) || tagLowerCase.startsWith(WO_START_TAG)) {
if (token.endsWith("/")) {
startOfWebObjectTag(token.substring(0, token.length() - 1));
endOfWebObjectTag("/");
} else {
startOfWebObjectTag(token);
}
} else if ((tagIndex = tagLowerCase.indexOf(WEBOBJECT_START_TAG)) > 1 || (tagIndex = tagLowerCase.indexOf(WO_COLON_START_TAG)) > 1 || (tagIndex = tagLowerCase.indexOf(WO_START_TAG)) > 1) {
_contentText.append(token.substring(0, token.lastIndexOf("<")));
if (token.endsWith("/")) {
startOfWebObjectTag(token.substring(tagIndex, token.length() - 1));
endOfWebObjectTag("/");
} else {
startOfWebObjectTag(token.substring(tagIndex, token.length()));
}
} else if (tagLowerCase.startsWith(WEBOBJECT_END_TAG) || tagLowerCase.startsWith(WO_COLON_END_TAG) || tagLowerCase.equals(WO_END_TAG)) {
endOfWebObjectTag(token);
} else if (tagLowerCase.startsWith(WOHelperFunctionHTMLParser.JS_START_TAG)) {
didParseText();
_contentText.append(token);
_contentText.append('>');
flag = false;
} else if (tagLowerCase.startsWith(WOHelperFunctionHTMLParser.JS_END_TAG)) {
didParseText();
_contentText.append(token);
_contentText.append('>');
flag = true;
} else if (token.startsWith("<!--") && flag) {
didParseText();
_contentText.append(token);
if (token.endsWith("--")) {
_contentText.append('>');
didParseComment();
} else {
_contentText.append('>');
parserState = STATE_INSIDE_COMMENT;
}
} else {
_contentText.append(token);
_contentText.append('>');
}
break;
case STATE_INSIDE_COMMENT:
token = templateTokenizer.nextToken(">");
_contentText.append(token);
_contentText.append('>');
if (token.endsWith("--")) {
didParseComment();
parserState = STATE_OUTSIDE;
}
break;
default:
break;
}
token = null;
if (parserState == STATE_OUTSIDE) {
token = templateTokenizer.nextToken("<");
}
} while (true);
} catch (NoSuchElementException e) {
log.error("No Such element dude", e);
didParseText();
return;
}
if (token != null) {
if (token.startsWith(">")) {
token = token.substring(1);
}
_contentText.append(token);
}
didParseText();
_stackDict = null;
}
use of com.webobjects.foundation.NSMutableDictionary in project wonder-slim by undur.
the class ERXMessageEncoding method setDefaultEncodingForLanguage.
private static void setDefaultEncodingForLanguage(String encoding, String language) {
if (!availableLanguages().containsObject(language)) {
throw createIllegalArgumentException(language, "language", "availableLanguages()");
}
if (!availableEncodings().containsObject(encoding)) {
throw createIllegalArgumentException(encoding, "encoding", "availableEncodings()");
}
NSMutableDictionary d = new NSMutableDictionary(_languagesAndDefaultEncodings);
d.setObjectForKey(encoding, language);
_languagesAndDefaultEncodings = d;
}
Aggregations