Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Format Paper Title and stuff to nice filename (See related posts)

Problem: How to cope with tons of papers to store?
Solution: Give them systemantic, human-readable filenames.
Syntax: author__title__mag_vol_year.pdf

rules:
* Author is turned to lowercase (easier to find where searching
is case sensitive)
* All non-alphanumeric-characters in the title will be turned
either into '_' or deleted.
* Append the magazine-abbev., the volume and the year - and
celebrate

   1  
   2  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   3      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
   4  <html xmlns="http://www.w3.org/1999/xhtml">
   5    <head>
   6  <script language="JavaScript1.1" type="text/javascript">
   7  //<![CDATA[
   8  // updateForm() and cleanMe() for cleanPaperFilename
   9  // 2007 by Sascha Tayefeh
  10  //
  11  // Problem: How to cope with tons of papers to store? 
  12  // Solution: Give them systemantic, human-readable filenames.
  13  // Syntax: author__title__mag_vol_year.pdf
  14  //
  15  // rules: 
  16  // * Author is turned to lowercase (easier to find where searching
  17  //   is case sensitive)
  18  // * All non-alphanumeric-characters in the title will be turned
  19  //   either into '_' or deleted.
  20  // * Append the magazine-abbev., the volume and the year - and 
  21  //   celebrate
  22  //
  23  
  24  function cleanMe(unpure)
  25  {
  26     var pure=unpure.replace(/[\s]/g,'_'); // First, replace all white-spaces by a single '_'
  27     pure=pure.replace(/[^_\d\w\-]/g,''); // Next, replace all invalid characters
  28     pure=pure.replace(/__*/g,'_'); // Clean up multiple '_'
  29     return pure;
  30  
  31  }
  32  
  33  function startForm()
  34  {
  35  	if(document.getElementById('npUpdate').checked) t=setTimeout('updateForm()',100);
  36  	else t=setTimeout('startForm()',200);
  37  }
  38  
  39  function npReset()
  40  {
  41   document.getElementById('title').value
  42     =document.getElementById('author').value
  43     =document.getElementById('mag').value
  44     =document.getElementById('vol').value
  45     =document.getElementById('pubYear').value
  46     ='';
  47     
  48  }
  49  
  50  function updateForm()
  51  {
  52     var green='#6f6';
  53     var red='#f66';
  54     var blue='#ccf';
  55     var grey='#ccc';
  56  
  57     var title=document.getElementById('title').value; // NOT .innerHTML, but actualle .value for textarea
  58     var author=document.getElementById('author').value;
  59     var mag=document.getElementById('mag').value;
  60     var vol=document.getElementById('vol').value;
  61     var pubYear=document.getElementById('pubYear').value;
  62     var output='';
  63  
  64  
  65     if (author) 
  66     {
  67        author=cleanMe(author).toLowerCase()+'__';
  68        document.getElementById('author').style.backgroundColor=green;
  69     } else document.getElementById('author').style.backgroundColor=grey;
  70  
  71     if (title) 
  72     {
  73        document.getElementById('title').style.backgroundColor=green;
  74        title=cleanMe(title)+"__";
  75     } else document.getElementById('title').style.backgroundColor=grey;
  76  
  77     if (mag) 
  78     {
  79        mag=cleanMe(mag)+"_";
  80        document.getElementById('mag').style.backgroundColor=green;
  81     } else document.getElementById('mag').style.backgroundColor=grey;
  82  
  83     if (vol && vol.match(/^\d+$/g) ) 
  84     {
  85        vol=vol+"_"; 
  86        document.getElementById('vol').style.backgroundColor=green; 
  87     } else if (vol && ! vol.match(/d+$/g) )
  88     { 
  89        vol=''; 
  90        document.getElementById('vol').style.backgroundColor=red; 
  91     } else document.getElementById('vol').style.backgroundColor=grey;
  92  
  93     if (pubYear && pubYear.match(/^\d+$/g) ) 
  94     {
  95        pubYear=pubYear+"_";
  96        document.getElementById('pubYear').style.backgroundColor=green; 
  97     }
  98     else if (pubYear && ! pubYear.match(/d+$/g) )
  99     { 
 100        pubYear=''; 
 101        document.getElementById('pubYear').style.backgroundColor=red; 
 102     } else document.getElementById('pubYear').style.backgroundColor=grey;
 103  
 104     // Assemble the filename string
 105     output=author +  title + mag  + vol + pubYear + '.pdf';
 106  
 107     if(output!='.pdf')
 108     {
 109        document.getElementById('output').innerHTML=output;
 110        document.getElementById('output').style.backgroundColor=blue;
 111     } else { 
 112        document.getElementById('output').innerHTML='';
 113        document.getElementById('output').style.backgroundColor=grey;
 114     }
 115  
 116    if(document.getElementById('npUpdate').checked) t=setTimeout('updateForm()',100);
 117    else t=setTimeout('startForm()',200);
 118  }
 119  
 120  
 121  
 122  //]]>
 123  </script>
 124  
 125      <meta name="generator" content="HTML Tidy for Linux/x86 (vers 1st November 2002), see www.w3.org" />
 126      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
 127      <title>Nice Paper Filenamer</title>
 128      <!-- StyleSheet -->
 129      <style type="text/css">
 130      /*<![CDATA[*/
 131  
 132  *
 133  {
 134  	 font-family: sans-serif;
 135  }
 136  
 137  body
 138  {
 139  	font-size: small;
 140  	padding: 2em;
 141  }
 142  
 143  dt
 144  {
 145  	font-weight: bold;
 146  }
 147  
 148  dd
 149  {
 150  	display: inline;
 151  }
 152  
 153  input, textarea
 154  {
 155     border: solid 1px;
 156     background-color: #ddd;
 157     font-size: small;
 158     font-family: monospace;
 159  }
 160      /*]]>*/
 161      </style>
 162  
 163    </head>
 164  
 165  <body onload="updateForm()">
 166  <div id="inputArea">
 167      <h1>Your Input</h1>
 168      <dl>
 169        <dt>Title: (going to be niced)</dt> <dd><textarea id="title"  rows="3" cols="100"  ></textarea> </dd>
 170        <dt>Main&nbsp;Author (only one, plz.):</dt> <dd><input id="author"  type="text"  size="100"  value="" /></dd>
 171  
 172        <dt>Magazine&nbsp;(Abbrev.):</dt> <dd><input id="mag" type="text"  size="100"  value="" /></dd>
 173        <dt>Volume: (integer only)</dt> <dd><input id="vol" type="text"  size="100"  value="" /></dd>
 174        <dt>PubYear: (integer only)</dt> <dd><input id="pubYear" type="text"  size="100"  value="" /></dd>
 175      </dl>
 176  </div>
 177  <div id="outputArea">
 178  
 179      <h1>My Output</h1>
 180      <dl>
 181   <dt style="display: inline;">Update Box:</dt><dd> <input id="npUpdate" type="checkbox" checked="checked" /></dd>
 182      <dt style="display: inline;">Reset input:</dt><dd> 
 183      <button id="npReset" type="button" onclick="npReset()">Reset</button</dd>
 184  <dt>Nice Filename:</dt><dd> <textarea id="output" rows="5" cols="100"></textarea></dd>
 185  </dl>
 186  </div>
 187  </body>
 188  </html>
 189  
 190  

You need to create an account or log in to post comments to this site.


Click here to browse all 5545 code snippets

Related Posts