📄 jsp_parser.y
字号:
}
break;
case JSP_SETPROPERTY:
switch (PG->act_attribute)
{
case JSP_NAME:
strcpy((char *)&(PG->bs.prop.name), (char *)pi3lval);
break;
case JSP_PROPERTY:
strcpy((char *)&(PG->bs.prop.property), (char *)pi3lval);
break;
case JSP_PROPERTYPARAM:
strcpy((char *)&(PG->bs.prop.param), (char *)pi3lval);
break;
case JSP_VALUE:
strcpy((char *)&(PG->bs.prop.value), (char *)pi3lval);
break;
default:
{
fprintf( PG->out, "\nPARSE ERROR\n");
// YYABORT;
};
}
break;
case JSP_USEBEAN:
switch (PG->act_attribute)
{
case JSP_ID:
strcpy((char *)&(PG->bs.bean.id), (char *)pi3lval);
break;
case JSP_SCOPE:
if (!strcmp("page", (char *)pi3lval)) strcpy((char *)&(PG->bs.bean.scope), "PAGE_SCOPE");
if (!strcmp("request", (char *)pi3lval)) strcpy((char *)&(PG->bs.bean.scope), "REQUEST_SCOPE");
if (!strcmp("session", (char *)pi3lval)) strcpy((char *)&(PG->bs.bean.scope), "SESSION_SCOPE");
if (!strcmp("application", (char *)pi3lval)) strcpy((char *)&(PG->bs.bean.scope), "APPLICATION_SCOPE");
break;
case JSP_CLASS:
strcpy((char *)&(PG->bs.bean.className), (char *)pi3lval);
break;
case JSP_TYPE:
strcpy((char *)&(PG->bs.bean.type), (char *)pi3lval);
break;
case JSP_BEANNAME:
strcpy((char *)&(PG->bs.bean.beanName), (char *)pi3lval);
break;
default:
{
fprintf( PG->out, "\nPARSE ERROR\n");
// YYABORT;
};
}
break;
case JSP_INCLUDE:
switch (PG->act_attribute)
{
case JSP_PAGE:
{
fprintf( PG->out, "\"%s\"", (char *)pi3lval);
break;
};
case JSP_FLUSH:
break; // we do nothing because flush=true is mandatory in JSP 1.0
default:
{
fprintf( PG->out, "\nPARSE ERROR\n");
// YYABORT;
};
};
break;
case JSP_FORWARD:
switch (PG->act_attribute)
{
case JSP_PAGE:
{
fprintf( PG->out, "\"%s\"", (char *)pi3lval);
break;
};
default:
{
fprintf( PG->out, "\nPARSE ERROR\n");
// YYABORT;
};
};
break;
default:
{
fprintf( PG->out, "\nPARSE ERROR\n");
// YYABORT;
};
};
};
}
;
jsp_end : ACTION_END
{
if (PG->pass)
{
switch (PG->action)
{
case JSP_GETPROPERTY:
fprintf( PG->out, "\t\t\tout.print(BeanProperty.get(%s,\"%s\"));\n",
PG->bs.prop.name, PG->bs.prop.property );
memset(&(PG->bs.bean), 0, sizeof(PG->bs.bean));
break;
case JSP_SETPROPERTY:
if ( PG->bs.prop.property[0] )
{
if (!strcmp(PG->bs.prop.property, "*"))
{
if ( PG->bs.prop.param[0] || PG->bs.prop.value[0] )
{
fprintf( PG->out, "\n/**\n* ERROR: Illegal options 'param' or 'value' \
in action jsp:setproperty.\n**/\n");
YYABORT;
};
}
else
{
if ( PG->bs.prop.param[0] && PG->bs.prop.value[0] )
{
fprintf( PG->out, "\n/**\n* ERROR: Illegal usage of 'param' and 'value' \
together in action jsp:setproperty.\n**/\n");
YYABORT;
};
};
pi3write_setproperty( PG );
memset(&(PG->bs.bean), 0, sizeof(PG->bs.bean));
}
else
{
fprintf( PG->out, "\n/**\n* ERROR: Missing mandatory parameter 'property' \
in action jsp:setproperty.\n**/\n");
// YYABORT;
};
break;
case JSP_USEBEAN:
if ( !PG->bs.bean.id[0] )
{
if (PG->pass) fprintf( PG->out, "\n/*\n* ERROR: Attribute 'id' is mandatory \
in JSP action 'usebean'.\n**/\n");
YYABORT;
};
if ( !PG->bs.bean.className[0] && !PG->bs.bean.type[0] )
{
if (PG->pass) fprintf( PG->out, "\n/*\n* ERROR: Either 'class' or 'type' \
has to be specified in JSP action 'usebean' with id '%s'.\n**/\n", PG->bs.bean.id);
YYABORT;
};
if ( PG->bs.bean.className[0] && PG->bs.bean.beanName[0] )
{
if (PG->pass) fprintf( PG->out, "\n/*\n* ERROR: Only either 'class' or 'beanName' \
allowed in JSP action 'usebean' with id '%s'.\n**/\n", PG->bs.bean.id);
YYABORT;
};
pi3write_bean(PG);
memset(&(PG->bs.bean), 0, sizeof(PG->bs.bean));
break;
case JSP_INCLUDE:
switch (PG->act_attribute)
{
case JSP_PAGE:
{
fprintf( PG->out, ").include(request, response);\n\t\t\tout.flush();\n\n");
break;
};
case JSP_FLUSH:
fprintf( PG->out, ").include(request, response);\n\t\t\tout.flush();\n\n");
break;
default:
{
break;
// YYABORT;
};
};
break;
case JSP_FORWARD:
switch (PG->act_attribute)
{
case JSP_PAGE:
{
fprintf( PG->out, ").forward(request, response);\n\n", (char *)pi3lval);
break;
};
default:
{
fprintf( PG->out, "\nPARSE ERROR\n");
// YYABORT;
};
};
break;
default:
{
fprintf( PG->out, "\nPARSE ERROR\n");
// YYABORT;
};
};
};
}
;
%%
int pi3servlet_head(void *YYPARSE_PARAM) {
const char *pValString;
assert(PG->out);
if (!PG->out) YYABORT;
fprintf( PG->out, "\
/**\n\
* Pi3Web Server 2.0\n\
* JSP version 1.0 bison parser $Revision: 1.17 $\n\
* $Date: 2003/05/13 18:42:19 $\n\
* Automatically generated code. Don't modify!\n\
* \n\
* Generated page header follows >>>>>\n\
**/\n"
);
fprintf( PG->out, "\
import java.io.*;\n\
import javax.servlet.*;\n\
import javax.servlet.http.*;\n\
import javax.servlet.jsp.*;\n\
import org.pi3.jsp.core.Pi3HttpJspPage;\n\
import org.pi3.jsp.runtime.*;\n\
\n\
// imports from page directives follow ...\n"
);
for (PG->import_ptr; PG->import_ptr;) fprintf( PG->out, "\
import %s;\n", PG->imports[--PG->import_ptr]
);
fprintf( PG->out, "\n\
public class %s extends %s", PG->classname, PG->extends);
pValString = (PG->isThreadSafe) ? "" : " implements SingleThreadModel";
fprintf( PG->out, pValString);
fprintf( PG->out, " {\n\
public void _jspService(HttpServletRequest request, HttpServletResponse response)\n\
throws IOException, ServletException {\n\
\n\
JspFactory factory = JspFactory.getDefaultFactory();\n\
PageContext pageContext = factory.getPageContext(\n\
this,\n\
request,\n\
response,\n"
);
fprintf( PG->out, "\
\"%s\", // errorPageURL\n", PG->errorPage);
pValString = (PG->session) ? "true" : "false";
fprintf( PG->out, "\
%s, // needsSession\n", pValString);
switch (PG->buffer) {
case -1:
fprintf( PG->out, "\
JspWriter.NO_BUFFER,\n"); break;
case 8:
fprintf( PG->out, "\
JspWriter.DEFAULT_BUFFER,\n"); break;
default:
fprintf( PG->out, "\
%d,\n", PG->buffer*1024);
};
pValString = (PG->autoFlush) ? "true" : "false";
fprintf( PG->out, "\
%s // autoFlush\n\
);\n\n", pValString);
fprintf( PG->out, "\
// initialize implicit variables for scripting env ...\n\
\n\
HttpSession session = pageContext.getSession();\n\
JspWriter out = pageContext.getOut();\n\
Object page = this;\n\
ServletContext application = pageContext.getServletContext();\n\
ServletConfig config = pageContext.getServletConfig();\n\
\n\
try {\n");
fprintf( PG->out, "/**\n* >>>>> End of generated page header\n");
fprintf( PG->out, "* Generated page contents follows >>>>>\n**/\n");
YYACCEPT;
}
int pi3servlet_foot(void *YYPARSE_PARAM) {
assert(PG->out);
if (!PG->out) YYABORT;
fprintf( PG->out, "/**\n* >>>>> End of generated page contents\n");
fprintf( PG->out, "* Generated page footer follows >>>>>\n**/\n");
fprintf( PG->out, "\
out.flush();\n\
} catch (Exception e) {\n\
out.clear();\n\
pageContext.handlePageException(e);\n\
} finally {\n\
out.close();\n\
factory.releasePageContext(pageContext);\n\
}\n\
}\n\
}\n"
);
YYACCEPT;
}
int pi3write_bean(void *YYPARSE_PARAM) {
if (PG->bs.bean.className[0])
{
fprintf( PG->out, "\t\t\t%s %s;\n", PG->bs.bean.className, PG->bs.bean.id );
}
else
{
fprintf( PG->out, "\t\t\t%s %s;\n", PG->bs.bean.type, PG->bs.bean.id );
}
if (!PG->bs.bean.scope[0] || (!strcmp(PG->bs.bean.scope, "page")))
{
fprintf( PG->out, "\t\t\t%s = (%s)pageContext.getAttribute(\"%s\");\n",
PG->bs.bean.id, PG->bs.bean.type, PG->bs.bean.id );
}
else
{
fprintf( PG->out, "\t\t\t%s = (%s)pageContext.getAttribute(\"%s\", pageContext.%s);\n",
PG->bs.bean.id, PG->bs.bean.type, PG->bs.bean.id, PG->bs.bean.scope );
}
fprintf( PG->out, "\t\t\tif (%s == null)\n", PG->bs.bean.id );
fprintf( PG->out, "\t\t\t\t{\n");
if (!PG->bs.bean.className[0] && !PG->bs.bean.beanName[0])
{
fprintf( PG->out, "\t\t\t\tClassCastException e = new ClassCastException(\
\"No class to instantiate bean with id %s\");\n", PG->bs.bean.id );
fprintf( PG->out, "\t\t\t\tthrow e;\n");
}
if (PG->bs.bean.className[0])
{
// T.B.D.: Check class and return InstantiationException, if
// class is abstract - class.forName().newInstance() ?
// class is interface - class.isInterface()
// class hasn't non-args constructor - class.getConstructor()
fprintf( PG->out, "\t\t\t\t%s = new %s();\n", PG->bs.bean.id, PG->bs.bean.className );
}
if (PG->bs.bean.beanName[0])
{
fprintf( PG->out, "\t\t\t\t%s = java.beans.Beans.instantiate(this.getClass().getClassLoader(), %s);\n",
PG->bs.bean.id, PG->bs.bean.beanName );
}
fprintf( PG->out, "\t\t\t\tif (%s != null)\n", PG->bs.bean.id );
fprintf( PG->out, "\t\t\t\t\t{\n");
fprintf( PG->out, "\t\t\t\t\tpageContext.setAttribute(\"%s\", %s, pageContext.%s);\n",
PG->bs.bean.id, PG->bs.bean.id, PG->bs.bean.scope );
fprintf( PG->out, "\t\t\t\t\t}\n");
fprintf( PG->out, "\t\t\t\t}\n\n");
YYACCEPT;
}
int pi3write_setproperty(void *YYPARSE_PARAM) {
if (!strcmp(PG->bs.prop.property, "*"))
{
fprintf( PG->out, "\t\t\tBeanProperty.set(%s,\"%s\",request);\n",
PG->bs.prop.name, PG->bs.prop.property );
}
else
{
if ( !PG->bs.prop.value[0] )
{
if ( PG->bs.prop.param[0] )
{
fprintf( PG->out, "\t\t\tBeanProperty.set(%s,\"%s\",request.getParameter(\"%s\"));\n",
PG->bs.prop.name, PG->bs.prop.property, PG->bs.prop.param );
}
else
{
fprintf( PG->out, "\t\t\tBeanProperty.set(%s,\"%s\",request.getParameter(\"%s\"));\n",
PG->bs.prop.name, PG->bs.prop.property, PG->bs.prop.property );
};
}
else
{
fprintf( PG->out, "\t\t\tBeanProperty.set(%s,\"%s\",\"%s\");\n",
PG->bs.prop.name, PG->bs.prop.property, PG->bs.prop.value );
}
};
YYACCEPT;
}
int pi3write_plain(void *YYPARSE_PARAM, const char *s) {
unsigned int i;
assert(PG->out&&s);
if (!PG->out || !s) YYABORT;
fputs( "\t\t\tout.print(\"", PG->out );
for ( i=0; i<strlen(s); i++ )
{
if ( s[i] == 0x22 )
{
if ( i==0 || ((i>0) && (s[i-1] != 0x5c)))
{
fputs( "\\\"", PG->out );
}
else
{
fputc( s[i], PG->out );
}
}
else
{
fputc( s[i], PG->out );
}
}
fputs( "\");\n", PG->out );
YYACCEPT;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -