class: ProcessScriptlet

public class: ProcessScriptlet
Author: makarenko (initial creation)
Project: Phase: 1.0; Status: Proposed; Version: $Revision: 146 $ $LastChangedDate: 2007-11-12 20:5; Complexity: 1
Dates: Created: 16.07.2009 15:12:35; Modified: 16.07.2009 15:12:35;
Flags: Active: false; IsRoot: false; IsLeaf: false;
Extension Points:
UUID: {E875975B-187D-4557-962C-C03FB2C5B1ED}
Generate Scriptlet class for repeatable elements processing
 

Goto: Custom Properties, Fields, Methods

See also: ProcessCitationStyles

Appears in: citationmanager

Connections
 
Custom Properties
 
ProcessScriptlet Attributes
Attribute Details
public static const boolean
  DEBUG
Initial: false
Notes: private static final Logger logger = Logger.getLogger(ProcessScriptlet.class);
private static const Logger
  logger
Initial: Logger.getLogger(ProcessScriptlet.class)
public static const String
  SCRIPTLET_CLASSNAME_PREFIX
Initial: "ScriptletForRepeatableElements"
public static String
  SCRIPTLET_XPATH_ROOT
Initial: null
Notes: TODO: should be moved directly to the CS definition
private String
  scriptletBody
Notes: scriptletBody for repeatable elements
public static const String
  scriptletBodyHeader
Initial: "package de.mpg.escidoc.services.citationmanager.scriptlets;\n" + "import net.sf.jasperreports.engine.JRDefaultScriptlet;\n" + // "import net.sf.jasperreports.engine.JRScriptletException;\n" + // "import net.sf.jasperreports.engine.JRAbstractScriptlet;\n" + "import net.sf.jasperreports.engine.data.JRXmlDataSource;\n" + "import net.sf.jasperreports.engine.design.JRDesignField;\n" + "import net.sf.jasperreports.engine.util.JRStringUtil;\n" + "import de.mpg.escidoc.services.citationmanager.utils.Utils;\n" + // "import org.w3c.dom.Document;\n" + // "import org.w3c.dom.Node;\n" + // "import java.util.StringTokenizer;\n" + // for func get_initials // "import java.util.ArrayList;\n\n" + "import java.util.*;\n" + "import java.util.regex.*;\n\n" + "public class %s extends JRDefaultScriptlet {\n" + "private ArrayList elems = new ArrayList();\n" + //<-- debug ( DEBUG ? "private long cTime = 0;\n" + "public String getCTime() {" + "return cTime + \"\";" + "}" : "" ) + //>-- debug "private String insertDelimiter(String left, String delim, String right) {\n" + " String result;\n" + " return (delim!=null && delim.length()>0 &&\n" + " left!=null && left.length()>0 &&\n" + " right!=null && right.length()>0 ) ? delim : \"\";\n" + "}\n" + "public String xmlEncode(String str) {\n" + " if (str!=null && str.length()>0) {\n" + // " str = JRStringUtil.xmlEncode(str);\n" + " str = JRStringUtil.xmlEncode(str);\n" + " }\n" + " return str;\n" + "}\n" + // "public void testString(String str) {\n" + // " for(char ch : str.toCharArray()) {\n" + // " System.out.print(\"ch:\"+ch+\",int:\"+((int)ch)+\";\");\n" + // " }\n" + // "}\n" + // Remove dublications of blanks, spaces and punctuation // TODO: check it! "public String cleanCit(String str) {\n" + " if (Utils.checkLen(str)) {\n" + // "System.out.println(\"before:\" + str);\n" + // "if ( str.indexOf(\"Working paper on research progress\")!=-1 ) {System.out.println(\"--1:\" + str);\n}" + // remove nulls // " str = str.replace(\"null\", \"\");\n" + // replace all \s with blank, new line as well everywhere in citation " str = Pattern.compile(\"[\\n\\r\\t]+\", Pattern.DOTALL).matcher(str).replaceAll(\" \");\n" + // remove empty styled text: " str = str.replaceAll(\"]*?>\\\\s*<[/]style[^>]*?>\",\"\");\n" + // remove empty snippet tags: // "System.out.println(\"--1:\" + str);\n" + " str = str.replaceAll(\"\\\\[span.*?\\\\]\\\\s*\\\\[/span\\\\]\",\"\");\n" + // replace all duplicated punctuations with the only one // "System.out.println(\"--2:\" + str);\n" + // " str = str.replaceAll(\"(([.,:;?!])+\\\\s*\\\\2)+\",\"$2\");\n" + " str = str.replaceAll(\"(\\\\s*[.]+)+\",\".\");\n" + " str = str.replaceAll(\"(\\\\s*[,]+)+\",\",\");\n" + " str = str.replaceAll(\"(\\\\s*[:]+)+\",\":\");\n" + " str = str.replaceAll(\"(\\\\s*[?]+)+\",\"?\");\n" + " str = str.replaceAll(\"(\\\\s*[!]+)+\",\"!\");\n" + " str = str.replaceAll(\"(\\\\s*[;]+)+\",\";\");\n" + // punctuation combinations: // remove dot after punctuations ([?!]). => $1 " str = str.replaceAll(\"([?!])\\\\s*[.]\",\"$1\");\n" + // remove all \s before punctuations (";" are excluded due to xml entities) // "System.out.println(\"--3:\" + str);\n" + // " str = str.replaceAll(\"\\\\s+([.,:;?!])\",\"$1\");\n" + // "if ( str.indexOf(\"Working paper on research progress\")!=-1 ) {testString(str);\n}" + // "if ( str.indexOf(\"Working paper on research progress\")!=-1 ) {System.out.println(\"--2:\" + str);\n}" + // next 2: ( 2007 ) to (2007) // "System.out.println(\"--4:\" + str);\n" + " str = str.replaceAll(\"([({<\\\\[])\\\\s+(.*)\",\"$1$2\");\n" + // "System.out.println(\"--5:\" + str);\n" + " str = str.replaceAll(\"(.*)\\\\s+([\\\\]>})])\",\"$1$2\");\n" + // "if ( str.indexOf(\"( 2008\")!=-1 ) {testString(str);\n}" + // "System.out.println(\"uge kaputt:\" + str);\n" + // "System.out.println(\"before2:\" + str);\n" + // " str = str.replaceAll(\"([,.;:?!])+(\\\\s)+(\\\\<[/]?style.*?\\\\>)(\\\\s)+([,.;:?!])+\",\"$1$2$3\");\n" + // "System.out.println(\"before3:\" + str);\n" + // "System.out.println(\"after:\" + str);\n" + // remove hanging punctuations round the style " str = str.replaceAll(\"(([.,;?!])+\\\\s*<[/]?style[^>]*?>)\\\\s*\\\\2+\",\"$1\");\n" + " str = str.replaceAll(\"\\\\s+(<[/]?style[^>]*?>)?\\\\s+\",\"$1 \");\n" + " str = str.replaceAll(\"\\\\s*(<[/]?style[^>]*?>)\\\\s*([.,;?!])\",\"$1$2\");\n" + // snippet clean up " str = str.replaceAll(\"(([.,;?!])+\\\\s*\\\\[[/]?span\\\\s*\\\\])\\\\s*\\\\2+\",\"$1\");\n" + " str = str.replaceAll(\"\\\\s+(\\\\[[/]?span\\\\s*\\\\])\\\\s+\",\"$1 \");\n" + " str = str.replaceAll(\"\\\\s*(\\\\[[/]?span\\\\s*\\\\])\\\\s*([.,;?!])\",\"$1$2\");\n" + // "if ( str.indexOf(\"Working paper on research progress\")!=-1 ) {System.out.println(\"--3:\" + str);\n}" + // "System.out.println(\"after2:\" + str);\n" + " }\n" + " return Utils.checkVal(str) ? str: null;\n" + "}\n"
private String
  scriptletClassName
Initial: null
public static Properties
  scriptletFunctions
Initial: null
Notes: table of special functions which can be applied in layout-elements (@func="funcname")
public static const String
  SCRIPTLETS_JAVA_DIRECTORY
Initial: "src/main/java/"
 
ProcessScriptlet Methods
Operation Details
public static
cleanUpScriptlets(
   String csName,
   String cssClassPostfix,
   boolean keepOldScriptlets):void
Sequential
Tags: throws=IllegalArgumentException,IOException,JRException
Notes: Deletes generated Scriptlet .java and .class for style <code>csName</code> in path <code>csPath</code>
@param csPath
public static
convertQNameToPath(
   String qname):String
Sequential
Notes: Converts QName to path: "/" instead of "."
@return path
public
createMethodForScriptlet(
   LayoutElement le,
   CitationStylesCollection csc,
   FontStylesCollection fsc):void
Sequential
Tags: throws=CitationStyleManagerException
Notes: Creates content for method which will be process repeatable LayoutElement le
@return HashMap with all fields to be inserted into Scriptlet method
public
generateScriptletClassName(
   String cs):String
Sequential
Notes: Generate and set uniq class name for scriptlet
@return generated scriptlet class name
private
getHeaderChunk(
   String name,
   String xPath):String
Sequential
private static
getJRDesignFieldsChunk(
   List elements,
   String pos):String
Sequential
Tags: throws=CitationStyleManagerException
public static
getPackageName():String
Sequential
Notes: Returns package name of the class
@return package name
public static
getPathToScriptletJava():String
Sequential
Tags: throws=IOException
Notes: Returns path to the scriptlet sources
@return path
public
getScriptletClassName():String
Sequential
Notes: Returns uniq class name of scriptlet
@return scriptlet class name
private static
getWhileFooterChunk(
   String pos,
   int maxCount):String
Sequential
private static
getWhileHeaderChunk(
   int maxCount,
   String maxCountEndsWith,
   String delimiter):String
Sequential
private static
getWhileInternalChunk(
   List elements,
   Parameters parameters,
   FontStylesCollection fsc,
   boolean flag):String
Sequential
Tags: throws=CitationStyleManagerException
Notes: Returns internal part of while loop according to position
@param position
@return String
private static
getXPath(
   LayoutElement le):String
Sequential
Notes: Get XPath for scriptlet's method. Criteria: 1) for repeatable elements takes xPath directly from @ref 2) for non-repeatable checks whether ref is in fieldsMap Otherwise returns 0
@return XPath
public static
isInScriptletFunctionsTable(
   String func):boolean
Sequential
Notes: checks whether func in scriptletFunctionsTable
@return true if func in scriptletFunctionsTable, false - otherwise
public
ProcessScriptlet(
   CitationStyle cs):
Sequential
Tags: throws=FileNotFoundException,IOException
public
ProcessScriptlet(
   CitationStyle cs,
   String postfix):
Sequential
Tags: throws=FileNotFoundException,IOException
public
writeToScriptlet():File
Sequential
Tags: throws=IOException
Notes: Writes scriptletBody to file
@param path
@param name