Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
*
* Portions Copyright Apache Software Foundation.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package org.apache.jasper.compiler;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import org.apache.jasper.JasperException;
import org.apache.jasper.JspCompilationContext;
/**
* Contains static utilities for generating SMAP data based on the
* current version of Jasper.
*
* @author Jayson Falkner
* @author Shawn Bayern
* @author Robert Field (inner SDEInstaller class)
* @author Mark Roth
* @author Kin-man Chung
*/
public class SmapUtil {
private JspCompilationContext ctxt;
private List classInfos;
//*********************************************************************
// Constants
public static final String SMAP_ENCODING = "UTF-8";
//*********************************************************************
// Public entry points
SmapUtil(JspCompilationContext ctxt) {
this.ctxt = ctxt;
}
/**
* Generates an appropriate SMAP representing the current compilation
* context. (JSR-045.)
*
* @param ctxt Current compilation context
* @param pageNodes The current JSP page
* @return a SMAP for the page
*/
public void generateSmap(Node.Nodes pageNodes)
throws IOException {
classInfos = new ArrayList();
String className = ctxt.getFullClassName();
// Instantiate a SmapStratum for the main JSP page.
SmapStratum s = new SmapStratum("JSP");
classInfos.add(new ClassInfo(className, s));
// Map out Node.Nodes and putting LineInfo into SmapStratum
evaluateNodes(pageNodes, s, ctxt.getOptions().getMappedFile());
String classFileName = ctxt.getClassFileName();
for (ClassInfo entry: classInfos) {
// Get SmapStratum
s = entry.getSmapStratum();
s.optimizeLineSection();
// Set up our SMAP generator
SmapGenerator g = new SmapGenerator();
g.setOutputFileName(unqualify(ctxt.getServletJavaFileName()));
g.addStratum(s, true);
String name = entry.getClassName(); // class name
// Compute the class name and output file name for inner classes
if (!className.equals(name)) {
classFileName = ctxt.getOutputDir() +
name.substring(name.lastIndexOf('.')+1) + ".class";
}
entry.setClassFileName(classFileName);
entry.setSmap(g.getString());
if (ctxt.getOptions().isSmapDumped()) {
File outSmap = new File(classFileName + ".smap");
PrintWriter so =
new PrintWriter(
new OutputStreamWriter(
new FileOutputStream(outSmap),
SMAP_ENCODING));
so.print(g.getString());
so.close();
}
}
}
public void installSmap() throws IOException {
for (ClassInfo ci: classInfos) {
String className = ci.getClassName();
byte[] classfile = ctxt.getRuntimeContext().getBytecode(className);
if (classfile == null) {
SDEInstaller.install(new File(ci.getClassFileName()),
ci.getSmap().getBytes());
}
else {
classfile = SDEInstaller.install(classfile,
ci.getSmap().getBytes());
ctxt.getRuntimeContext().setBytecode(className, classfile);
}
}
}
//*********************************************************************
// Private utilities
/**
* Returns an unqualified version of the given file path.
*/
private static String unqualify(String path) {
path = path.replace('\\', '/');
return path.substring(path.lastIndexOf('/') + 1);
}
//*********************************************************************
// Installation logic (from Robert Field, JSR-045 spec lead)
private static class SDEInstaller {
static final String nameSDE = "SourceDebugExtension";
byte[] orig;
byte[] sdeAttr;
byte[] gen;
int origPos = 0;
int genPos = 0;
int sdeIndex;
public static void main(String[] args) throws IOException {
if (args.length == 2) {
install(new File(args[0]), new File(args[1]));
} else if (args.length == 3) {
install(
new File(args[0]),
new File(args[1]),
new File(args[2]));
} else {
System.err.println(
"Usage: "
+ "