Reduced line indent from 3 to 2 spaces
This commit is contained in:
parent
3e769d3d6e
commit
c7d78eba65
85 changed files with 13354 additions and 13354 deletions
510
build.xml
510
build.xml
|
@ -13,7 +13,7 @@
|
|||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
|
@ -28,291 +28,291 @@
|
|||
-->
|
||||
|
||||
<project name="antville" default="usage" basedir=".">
|
||||
<target name="help" depends="usage"/>
|
||||
<target name="usage">
|
||||
<echo message="Antville Build Instructions"/>
|
||||
<echo message="==========================="/>
|
||||
<echo message="Available targets are:"/>
|
||||
<echo message=" all Generate the Antville and AntClick packages"/>
|
||||
<echo message=" antville Generate the Antville packages"/>
|
||||
<echo message=" antclick Generate the AntClick packages"/>
|
||||
<echo message=" release Copy packages to the download server"/>
|
||||
<echo message=" docs Generate the API documentation"/>
|
||||
<echo message=" pot Extract gettext call strings into POT file"/>
|
||||
<echo message=" messages Generate JavaScript message files"/>
|
||||
<echo message=" clean Clean up build directory"/>
|
||||
<echo message=" patch Apply patch file to Antville installation"/>
|
||||
<echo message=" usage Show these build instructions (default)"/>
|
||||
</target>
|
||||
<target name="help" depends="usage"/>
|
||||
<target name="usage">
|
||||
<echo message="Antville Build Instructions"/>
|
||||
<echo message="==========================="/>
|
||||
<echo message="Available targets are:"/>
|
||||
<echo message=" all Generate the Antville and AntClick packages"/>
|
||||
<echo message=" antville Generate the Antville packages"/>
|
||||
<echo message=" antclick Generate the AntClick packages"/>
|
||||
<echo message=" release Copy packages to the download server"/>
|
||||
<echo message=" docs Generate the API documentation"/>
|
||||
<echo message=" pot Extract gettext call strings into POT file"/>
|
||||
<echo message=" messages Generate JavaScript message files"/>
|
||||
<echo message=" clean Clean up build directory"/>
|
||||
<echo message=" patch Apply patch file to Antville installation"/>
|
||||
<echo message=" usage Show these build instructions (default)"/>
|
||||
</target>
|
||||
|
||||
<target name="all" depends="antville, antclick"/>
|
||||
<target name="all" depends="antville, antclick"/>
|
||||
|
||||
<target name="init">
|
||||
<tstamp>
|
||||
<format property="date" pattern="d MMM yyyy" locale="en"/>
|
||||
</tstamp>
|
||||
<target name="init">
|
||||
<tstamp>
|
||||
<format property="date" pattern="d MMM yyyy" locale="en"/>
|
||||
</tstamp>
|
||||
|
||||
<property name="name" value="antville"/>
|
||||
<property name="year" value="1998-${year}"/>
|
||||
<property name="version" value="1.4"/>
|
||||
<property name="package.name" value="${name}-${version}"/>
|
||||
<property name="name" value="antville"/>
|
||||
<property name="year" value="1998-${year}"/>
|
||||
<property name="version" value="1.4"/>
|
||||
<property name="package.name" value="${name}-${version}"/>
|
||||
|
||||
<property name="antville.src" value="http://antville.googlecode.com/svn/trunk"/>
|
||||
<property name="helma.src" value="https://github.com/p3k/helma/trunk"/>
|
||||
<property name="modules.src" value="https://github.com/p3k/helma-modules/trunk"/>
|
||||
<property name="apps.src" value="https://github.com/p3k/helma-apps/trunk"/>
|
||||
<property name="jala.src" value="https://github.com/p3k/helma-jala/trunk"/>
|
||||
<property name="antville.src" value="http://antville.googlecode.com/svn/trunk"/>
|
||||
<property name="helma.src" value="https://github.com/p3k/helma/trunk"/>
|
||||
<property name="modules.src" value="https://github.com/p3k/helma-modules/trunk"/>
|
||||
<property name="apps.src" value="https://github.com/p3k/helma-apps/trunk"/>
|
||||
<property name="jala.src" value="https://github.com/p3k/helma-jala/trunk"/>
|
||||
|
||||
<property name="build.dir" location="${basedir}/build"/>
|
||||
<property file="${build.dir}/build.properties"/>
|
||||
<property name="build.dir" location="${basedir}/build"/>
|
||||
<property file="${build.dir}/build.properties"/>
|
||||
|
||||
<property name="helma.dir" location="/opt/helma"/>
|
||||
<property name="extra.dir" location="${build.dir}/extra"/>
|
||||
<property name="dist.dir" location="${build.dir}/dist"/>
|
||||
<property name="work.dir" location="${build.dir}/work"/>
|
||||
<property name="export.dir" location="${work.dir}/export"/>
|
||||
<property name="modules.dir" location="${work.dir}/modules"/>
|
||||
<property name="apps.dir" location="${work.dir}/apps"/>
|
||||
<property name="antville.dir" location="${apps.dir}/antville"/>
|
||||
<property name="hopkit.dir" location="${helma.dir}/modules/jala/util/HopKit"/>
|
||||
<property name="helma.dir" location="/opt/helma"/>
|
||||
<property name="extra.dir" location="${build.dir}/extra"/>
|
||||
<property name="dist.dir" location="${build.dir}/dist"/>
|
||||
<property name="work.dir" location="${build.dir}/work"/>
|
||||
<property name="export.dir" location="${work.dir}/export"/>
|
||||
<property name="modules.dir" location="${work.dir}/modules"/>
|
||||
<property name="apps.dir" location="${work.dir}/apps"/>
|
||||
<property name="antville.dir" location="${apps.dir}/antville"/>
|
||||
<property name="hopkit.dir" location="${helma.dir}/modules/jala/util/HopKit"/>
|
||||
|
||||
<property name="docs.title" value="Antville&#32;${version}&#32;API&#32;Reference"/>
|
||||
<property name="docs.infiles" location="${basedir}/code"/>
|
||||
<property name="docs.outfiles" location="${basedir}/docs"/>
|
||||
<property name="docs.title" value="Antville&#32;${version}&#32;API&#32;Reference"/>
|
||||
<property name="docs.infiles" location="${basedir}/code"/>
|
||||
<property name="docs.outfiles" location="${basedir}/docs"/>
|
||||
|
||||
<property name="i18n.scan" value="code compat extra"/>
|
||||
<property name="i18n.destination" location="${basedir}/i18n"/>
|
||||
<property name="i18n.poDirectory" location="${i18n.destination}"/>
|
||||
<property name="i18n.template" location="${i18n.destination}/antville.pot"/>
|
||||
<property name="i18n.namespace" value=""/>
|
||||
</target>
|
||||
<property name="i18n.scan" value="code compat extra"/>
|
||||
<property name="i18n.destination" location="${basedir}/i18n"/>
|
||||
<property name="i18n.poDirectory" location="${i18n.destination}"/>
|
||||
<property name="i18n.template" location="${i18n.destination}/antville.pot"/>
|
||||
<property name="i18n.namespace" value=""/>
|
||||
</target>
|
||||
|
||||
<target name="export" depends="init">
|
||||
<mkdir dir="${export.dir}"/>
|
||||
<mkdir dir="${apps.dir}"/>
|
||||
<exec dir="${apps.dir}" executable="svn">
|
||||
<arg line="--force export --ignore-externals ${antville.src} antville"/>
|
||||
</exec>
|
||||
<delete includeemptydirs="true">
|
||||
<fileset dir="${antville.dir}" includes="build.xml build/** docs/** i18n/*.po*"/>
|
||||
</delete>
|
||||
<exec dir="${build.dir}" executable="sh" outputproperty="revision">
|
||||
<arg value="-c"/>
|
||||
<arg value="svn info ${antville.src} | awk "/Last Changed Rev:/"'{print $4;}'"/>
|
||||
</exec>
|
||||
<replace file="${antville.dir}/code/Root/Root.js" token="@version@" value="${version}"/>
|
||||
<replace file="${antville.dir}/code/Root/Root.js" token="@revision@" value="${revision}"/>
|
||||
<replace file="${antville.dir}/code/Root/Root.js" token="@buildDate@" value="${date}"/>
|
||||
</target>
|
||||
<target name="export" depends="init">
|
||||
<mkdir dir="${export.dir}"/>
|
||||
<mkdir dir="${apps.dir}"/>
|
||||
<exec dir="${apps.dir}" executable="svn">
|
||||
<arg line="--force export --ignore-externals ${antville.src} antville"/>
|
||||
</exec>
|
||||
<delete includeemptydirs="true">
|
||||
<fileset dir="${antville.dir}" includes="build.xml build/** docs/** i18n/*.po*"/>
|
||||
</delete>
|
||||
<exec dir="${build.dir}" executable="sh" outputproperty="revision">
|
||||
<arg value="-c"/>
|
||||
<arg value="svn info ${antville.src} | awk "/Last Changed Rev:/"'{print $4;}'"/>
|
||||
</exec>
|
||||
<replace file="${antville.dir}/code/Root/Root.js" token="@version@" value="${version}"/>
|
||||
<replace file="${antville.dir}/code/Root/Root.js" token="@revision@" value="${revision}"/>
|
||||
<replace file="${antville.dir}/code/Root/Root.js" token="@buildDate@" value="${date}"/>
|
||||
</target>
|
||||
|
||||
<target name="ville" depends="antville"/>
|
||||
<target name="antville" depends="export">
|
||||
<antcall target="make-tar">
|
||||
<param name="filename" value="${package.name}"/>
|
||||
<param name="path" value="${antville.dir}"/>
|
||||
</antcall>
|
||||
<antcall target="make-zip">
|
||||
<param name="filename" value="${package.name}"/>
|
||||
<param name="path" value="${antville.dir}"/>
|
||||
</antcall>
|
||||
</target>
|
||||
<target name="ville" depends="antville"/>
|
||||
<target name="antville" depends="export">
|
||||
<antcall target="make-tar">
|
||||
<param name="filename" value="${package.name}"/>
|
||||
<param name="path" value="${antville.dir}"/>
|
||||
</antcall>
|
||||
<antcall target="make-zip">
|
||||
<param name="filename" value="${package.name}"/>
|
||||
<param name="path" value="${antville.dir}"/>
|
||||
</antcall>
|
||||
</target>
|
||||
|
||||
<target name="click" depends="antclick"/>
|
||||
<target name="antclick" depends="export">
|
||||
<target name="click" depends="antclick"/>
|
||||
<target name="antclick" depends="export">
|
||||
|
||||
<!-- Export Helma, modules and apps to temporary directory -->
|
||||
<exec dir="${export.dir}" executable="svn">
|
||||
<arg line="--force export ${helma.src} helma"/>
|
||||
</exec>
|
||||
<exec dir="${export.dir}" executable="svn">
|
||||
<arg line="--force export ${modules.src} modules"/>
|
||||
</exec>
|
||||
<exec dir="${export.dir}" executable="svn">
|
||||
<arg line="--force export ${jala.src} modules/jala"/>
|
||||
</exec>
|
||||
<exec dir="${export.dir}" executable="svn">
|
||||
<arg line="--force export ${apps.src} apps"/>
|
||||
</exec>
|
||||
<!-- Export Helma, modules and apps to temporary directory -->
|
||||
<exec dir="${export.dir}" executable="svn">
|
||||
<arg line="--force export ${helma.src} helma"/>
|
||||
</exec>
|
||||
<exec dir="${export.dir}" executable="svn">
|
||||
<arg line="--force export ${modules.src} modules"/>
|
||||
</exec>
|
||||
<exec dir="${export.dir}" executable="svn">
|
||||
<arg line="--force export ${jala.src} modules/jala"/>
|
||||
</exec>
|
||||
<exec dir="${export.dir}" executable="svn">
|
||||
<arg line="--force export ${apps.src} apps"/>
|
||||
</exec>
|
||||
|
||||
<!-- Copy exported files to final destinations -->
|
||||
<copy todir="${work.dir}">
|
||||
<fileset dir="${export.dir}/helma" includes="lib/** licenses/**"/>
|
||||
</copy>
|
||||
<copy todir="${modules.dir}">
|
||||
<fileset dir="${export.dir}/modules" includes="core/** helma/** jala/**"/>
|
||||
</copy>
|
||||
<copy todir="${apps.dir}">
|
||||
<fileset dir="${export.dir}/apps" includes="manage/**"/>
|
||||
</copy>
|
||||
<!-- Copy exported files to final destinations -->
|
||||
<copy todir="${work.dir}">
|
||||
<fileset dir="${export.dir}/helma" includes="lib/** licenses/**"/>
|
||||
</copy>
|
||||
<copy todir="${modules.dir}">
|
||||
<fileset dir="${export.dir}/modules" includes="core/** helma/** jala/**"/>
|
||||
</copy>
|
||||
<copy todir="${apps.dir}">
|
||||
<fileset dir="${export.dir}/apps" includes="manage/**"/>
|
||||
</copy>
|
||||
|
||||
<copy file="${export.dir}/helma/license.txt" tofile="${work.dir}/licenses/helma.txt"/>
|
||||
<copy file="${export.dir}/helma/license.txt" tofile="${work.dir}/licenses/helma.txt"/>
|
||||
|
||||
<!-- Copy extra files to final destinations -->
|
||||
<copy todir="${work.dir}">
|
||||
<fileset dir="${extra.dir}" includes="start.bat apps.properties
|
||||
server.properties launcher.jar"/>
|
||||
</copy>
|
||||
<exec dir="${extra.dir}" executable="cp">
|
||||
<arg line="-p start.sh ${work.dir}"/>
|
||||
</exec>
|
||||
<!-- Copy extra files to final destinations -->
|
||||
<copy todir="${work.dir}">
|
||||
<fileset dir="${extra.dir}" includes="start.bat apps.properties
|
||||
server.properties launcher.jar"/>
|
||||
</copy>
|
||||
<exec dir="${extra.dir}" executable="cp">
|
||||
<arg line="-p start.sh ${work.dir}"/>
|
||||
</exec>
|
||||
|
||||
<copy file="${extra.dir}/helma.jar" todir="${work.dir}/lib"/>
|
||||
<copy file="${extra.dir}/h2-1.3.155.jar" todir="${work.dir}/lib/ext"/>
|
||||
<copy file="${extra.dir}/h2.txt" todir="${work.dir}/licenses"/>
|
||||
<copy file="${extra.dir}/helma.jar" todir="${work.dir}/lib"/>
|
||||
<copy file="${extra.dir}/h2-1.3.155.jar" todir="${work.dir}/lib/ext"/>
|
||||
<copy file="${extra.dir}/h2.txt" todir="${work.dir}/licenses"/>
|
||||
|
||||
<copy todir="${build.dir}/work/db">
|
||||
<fileset dir="${extra.dir}" includes="antville.h2.db"/>
|
||||
</copy>
|
||||
<copy todir="${work.dir}/licenses">
|
||||
<fileset dir="${antville.dir}/legal" includes="**"/>
|
||||
</copy>
|
||||
<copy file="${modules.dir}/jala/licenses/jala.txt" todir="${work.dir}/licenses"/>
|
||||
<copy todir="${build.dir}/work/db">
|
||||
<fileset dir="${extra.dir}" includes="antville.h2.db"/>
|
||||
</copy>
|
||||
<copy todir="${work.dir}/licenses">
|
||||
<fileset dir="${antville.dir}/legal" includes="**"/>
|
||||
</copy>
|
||||
<copy file="${modules.dir}/jala/licenses/jala.txt" todir="${work.dir}/licenses"/>
|
||||
|
||||
<!-- Delete unnecessary files -->
|
||||
<delete>
|
||||
<fileset dir="${modules.dir}/helma" includes="*.jar Search.js Ssh.js Chart.js"/>
|
||||
</delete>
|
||||
<delete includeemptydirs="true">
|
||||
<fileset dir="${modules.dir}/jala" includes="build.properties docs/**
|
||||
lib/** licenses/** tests/** util/**"/>
|
||||
</delete>
|
||||
<!-- Delete unnecessary files -->
|
||||
<delete>
|
||||
<fileset dir="${modules.dir}/helma" includes="*.jar Search.js Ssh.js Chart.js"/>
|
||||
</delete>
|
||||
<delete includeemptydirs="true">
|
||||
<fileset dir="${modules.dir}/jala" includes="build.properties docs/**
|
||||
lib/** licenses/** tests/** util/**"/>
|
||||
</delete>
|
||||
|
||||
<delete dir="${antville.dir}/legal"/>
|
||||
<delete dir="${export.dir}"/>
|
||||
<delete dir="${antville.dir}/legal"/>
|
||||
<delete dir="${export.dir}"/>
|
||||
|
||||
<!-- Create the packages -->
|
||||
<antcall target="make-zip">
|
||||
<param name="filename" value="antclick-${version}"/>
|
||||
<param name="path" value="${work.dir}"/>
|
||||
</antcall>
|
||||
<antcall target="make-tar">
|
||||
<param name="filename" value="antclick-${version}"/>
|
||||
<param name="path" value="${work.dir}"/>
|
||||
</antcall>
|
||||
</target>
|
||||
<!-- Create the packages -->
|
||||
<antcall target="make-zip">
|
||||
<param name="filename" value="antclick-${version}"/>
|
||||
<param name="path" value="${work.dir}"/>
|
||||
</antcall>
|
||||
<antcall target="make-tar">
|
||||
<param name="filename" value="antclick-${version}"/>
|
||||
<param name="path" value="${work.dir}"/>
|
||||
</antcall>
|
||||
</target>
|
||||
|
||||
<target name="docs" depends="init">
|
||||
<exec dir="${build.dir}/jsdoc/toolkit" executable="${build.dir}/jsdoc/jsrunwrapper.sh">
|
||||
<arg line='-D="title:${docs.title}" -q -r=2 -p -t=../templates/codeview
|
||||
<target name="docs" depends="init">
|
||||
<exec dir="${build.dir}/jsdoc/toolkit" executable="${build.dir}/jsdoc/jsrunwrapper.sh">
|
||||
<arg line='-D="title:${docs.title}" -q -r=2 -p -t=../templates/codeview
|
||||
-d=${docs.outfiles} ${docs.infiles}'/>
|
||||
</exec>
|
||||
</target>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="pot" depends="init">
|
||||
<java dir="${helma.dir}" classpath="${helma.dir}/launcher.jar" classname="helma.main.launcher.Commandline"
|
||||
fork="true">
|
||||
<!-- Root.extractMessages is currently located in Global/i18n.js -->
|
||||
<arg value="antville.extractMessages"/>
|
||||
<arg value="${build.dir}/MessageParser.js"/>
|
||||
<arg value="${i18n.scan}"/>
|
||||
<arg value="${i18n.template}"/>
|
||||
</java>
|
||||
</target>
|
||||
<target name="pot" depends="init">
|
||||
<java dir="${helma.dir}" classpath="${helma.dir}/launcher.jar" classname="helma.main.launcher.Commandline"
|
||||
fork="true">
|
||||
<!-- Root.extractMessages is currently located in Global/i18n.js -->
|
||||
<arg value="antville.extractMessages"/>
|
||||
<arg value="${build.dir}/MessageParser.js"/>
|
||||
<arg value="${i18n.scan}"/>
|
||||
<arg value="${i18n.template}"/>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<target name="messages" depends="init">
|
||||
<java dir="${helma.dir}" classpath="${helma.dir}/lib/rhino.jar"
|
||||
classname="org.mozilla.javascript.tools.shell.Main">
|
||||
<arg value="${build.dir}/PoParser.js"/>
|
||||
<arg value="${i18n.poDirectory}"/>
|
||||
<arg value="${i18n.destination}"/>
|
||||
<arg value="${i18n.namespace}"/>
|
||||
</java>
|
||||
</target>
|
||||
<target name="messages" depends="init">
|
||||
<java dir="${helma.dir}" classpath="${helma.dir}/lib/rhino.jar"
|
||||
classname="org.mozilla.javascript.tools.shell.Main">
|
||||
<arg value="${build.dir}/PoParser.js"/>
|
||||
<arg value="${i18n.poDirectory}"/>
|
||||
<arg value="${i18n.destination}"/>
|
||||
<arg value="${i18n.namespace}"/>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<target name="make-tar" depends="init">
|
||||
<mkdir dir="${dist.dir}"/>
|
||||
<fixcrlf srcdir="${path}" eol="lf" eof="remove" includes="**/*.txt,
|
||||
**/*.properties, **/*.hac, **/*.js, **/*.skin, **/.xml, **/.sh"/>
|
||||
<tar tarfile="${dist.dir}/${filename}.tar" basedir="${path}" excludes="**">
|
||||
<tarfileset prefix="${filename}" dir="${path}" mode="755">
|
||||
<include name="**/*.sh"/>
|
||||
</tarfileset>
|
||||
<tarfileset prefix="${filename}" dir="${path}">
|
||||
<include name="**"/>
|
||||
<exclude name="**/*.sh"/>
|
||||
</tarfileset>
|
||||
</tar>
|
||||
<bzip2 zipfile="${dist.dir}/${filename}.tbz" src="${dist.dir}/${filename}.tar"/>
|
||||
<delete file="${dist.dir}/${filename}.tar"/>
|
||||
</target>
|
||||
<target name="make-tar" depends="init">
|
||||
<mkdir dir="${dist.dir}"/>
|
||||
<fixcrlf srcdir="${path}" eol="lf" eof="remove" includes="**/*.txt,
|
||||
**/*.properties, **/*.hac, **/*.js, **/*.skin, **/.xml, **/.sh"/>
|
||||
<tar tarfile="${dist.dir}/${filename}.tar" basedir="${path}" excludes="**">
|
||||
<tarfileset prefix="${filename}" dir="${path}" mode="755">
|
||||
<include name="**/*.sh"/>
|
||||
</tarfileset>
|
||||
<tarfileset prefix="${filename}" dir="${path}">
|
||||
<include name="**"/>
|
||||
<exclude name="**/*.sh"/>
|
||||
</tarfileset>
|
||||
</tar>
|
||||
<bzip2 zipfile="${dist.dir}/${filename}.tbz" src="${dist.dir}/${filename}.tar"/>
|
||||
<delete file="${dist.dir}/${filename}.tar"/>
|
||||
</target>
|
||||
|
||||
<target name="make-zip" depends="init">
|
||||
<mkdir dir="${dist.dir}"/>
|
||||
<fixcrlf srcdir="${path}" eol="crlf" includes="**/*.txt, **/*.properties,
|
||||
**/*.hac, **/*.js, **/*.skin, **/*.xml, **/.bat"/>
|
||||
<zip zipfile="${dist.dir}/${filename}.zip">
|
||||
<zipfileset dir="${path}" prefix="${filename}" includes="**"/>
|
||||
</zip>
|
||||
</target>
|
||||
<target name="make-zip" depends="init">
|
||||
<mkdir dir="${dist.dir}"/>
|
||||
<fixcrlf srcdir="${path}" eol="crlf" includes="**/*.txt, **/*.properties,
|
||||
**/*.hac, **/*.js, **/*.skin, **/*.xml, **/.bat"/>
|
||||
<zip zipfile="${dist.dir}/${filename}.zip">
|
||||
<zipfileset dir="${path}" prefix="${filename}" includes="**"/>
|
||||
</zip>
|
||||
</target>
|
||||
|
||||
<target name="release" depends="init">
|
||||
<property name="antville.summary"
|
||||
value="Helma application providing high performance, full featured weblog hosting"/>
|
||||
<property name="antclick.summary"
|
||||
value="The lightweight all-in-one package which contains everything you need to run Antville on your computer"/>
|
||||
<antcall target="upload">
|
||||
<param name="file" value="${dist.dir}/${package.name}.tbz"/>
|
||||
<param name="summary" value="${antville.summary}"/>
|
||||
<param name="labels" value="Type-Package, OpSys-All, Featured"/>
|
||||
</antcall>
|
||||
<antcall target="upload">
|
||||
<param name="file" value="${dist.dir}/${package.name}.zip"/>
|
||||
<param name="summary" value="${antville.summary}"/>
|
||||
<param name="labels" value="Type-Package, OpSys-Windows"/>
|
||||
</antcall>
|
||||
<antcall target="upload">
|
||||
<param name="file" value="${dist.dir}/antclick-${version}.tbz"/>
|
||||
<param name="summary" value="${antclick.summary}"/>
|
||||
<param name="labels" value="Type-Package, OpSys-All"/>
|
||||
</antcall>
|
||||
<antcall target="upload">
|
||||
<param name="file" value="${dist.dir}/antclick-${version}.zip"/>
|
||||
<param name="summary" value="${antclick.summary}"/>
|
||||
<param name="labels" value="Type-Package, OpSys-Windows, Featured"/>
|
||||
</antcall>
|
||||
</target>
|
||||
<target name="release" depends="init">
|
||||
<property name="antville.summary"
|
||||
value="Helma application providing high performance, full featured weblog hosting"/>
|
||||
<property name="antclick.summary"
|
||||
value="The lightweight all-in-one package which contains everything you need to run Antville on your computer"/>
|
||||
<antcall target="upload">
|
||||
<param name="file" value="${dist.dir}/${package.name}.tbz"/>
|
||||
<param name="summary" value="${antville.summary}"/>
|
||||
<param name="labels" value="Type-Package, OpSys-All, Featured"/>
|
||||
</antcall>
|
||||
<antcall target="upload">
|
||||
<param name="file" value="${dist.dir}/${package.name}.zip"/>
|
||||
<param name="summary" value="${antville.summary}"/>
|
||||
<param name="labels" value="Type-Package, OpSys-Windows"/>
|
||||
</antcall>
|
||||
<antcall target="upload">
|
||||
<param name="file" value="${dist.dir}/antclick-${version}.tbz"/>
|
||||
<param name="summary" value="${antclick.summary}"/>
|
||||
<param name="labels" value="Type-Package, OpSys-All"/>
|
||||
</antcall>
|
||||
<antcall target="upload">
|
||||
<param name="file" value="${dist.dir}/antclick-${version}.zip"/>
|
||||
<param name="summary" value="${antclick.summary}"/>
|
||||
<param name="labels" value="Type-Package, OpSys-Windows, Featured"/>
|
||||
</antcall>
|
||||
</target>
|
||||
|
||||
<target name="test-upload" depends="init">
|
||||
<antcall target="upload">
|
||||
<param name="file" value="/Users/tobi/Desktop/test.txt"/>
|
||||
<param name="summary" value="Test pls ignore"/>
|
||||
<param name="labels" value="Deprecated"/>
|
||||
</antcall>
|
||||
</target>
|
||||
<target name="test-upload" depends="init">
|
||||
<antcall target="upload">
|
||||
<param name="file" value="/Users/tobi/Desktop/test.txt"/>
|
||||
<param name="summary" value="Test pls ignore"/>
|
||||
<param name="labels" value="Deprecated"/>
|
||||
</antcall>
|
||||
</target>
|
||||
|
||||
<target name="upload" depends="file-exists" if="file.exists">
|
||||
<taskdef classname="net.bluecow.googlecode.ant.GoogleCodeUploadTask"
|
||||
classpath="${build.dir}/ant-googlecode-0.0.3.jar" name="gcupload"/>
|
||||
<gcupload username="${google.username}" password="${google.password}" projectname="antville" filename="${file}"
|
||||
targetfilename="${file}" summary="${summary}" labels="${labels}"/>
|
||||
</target>
|
||||
<target name="upload" depends="file-exists" if="file.exists">
|
||||
<taskdef classname="net.bluecow.googlecode.ant.GoogleCodeUploadTask"
|
||||
classpath="${build.dir}/ant-googlecode-0.0.3.jar" name="gcupload"/>
|
||||
<gcupload username="${google.username}" password="${google.password}" projectname="antville" filename="${file}"
|
||||
targetfilename="${file}" summary="${summary}" labels="${labels}"/>
|
||||
</target>
|
||||
|
||||
<target name="patch" depends="init">
|
||||
<input message="Please enter the patch ID: " addproperty="patch.id"/>
|
||||
<loadfile property="patch" srcFile="${basedir}/extra/updater/patch-${patch.id}.js"/>
|
||||
<echo message="${patch}"/>
|
||||
<input message="Apply the displayed patch? " validargs="y,n" addproperty="patch.confirm"/>
|
||||
<condition property="patch.abort">
|
||||
<equals arg1="${patch.confirm}" arg2="n" casesensitive="false" trim="true"/>
|
||||
</condition>
|
||||
<fail if="patch.abort">Build aborted by user.</fail>
|
||||
<java dir="${helma.dir}" classpath="${helma.dir}/launcher.jar" classname="helma.main.launcher.Commandline"
|
||||
fork="true">
|
||||
<arg value="antville.patch"/>
|
||||
<arg value="${patch}"/>
|
||||
</java>
|
||||
</target>
|
||||
<target name="patch" depends="init">
|
||||
<input message="Please enter the patch ID: " addproperty="patch.id"/>
|
||||
<loadfile property="patch" srcFile="${basedir}/extra/updater/patch-${patch.id}.js"/>
|
||||
<echo message="${patch}"/>
|
||||
<input message="Apply the displayed patch? " validargs="y,n" addproperty="patch.confirm"/>
|
||||
<condition property="patch.abort">
|
||||
<equals arg1="${patch.confirm}" arg2="n" casesensitive="false" trim="true"/>
|
||||
</condition>
|
||||
<fail if="patch.abort">Build aborted by user.</fail>
|
||||
<java dir="${helma.dir}" classpath="${helma.dir}/launcher.jar" classname="helma.main.launcher.Commandline"
|
||||
fork="true">
|
||||
<arg value="antville.patch"/>
|
||||
<arg value="${patch}"/>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<target name="clean" depends="init">
|
||||
<delete dir="${work.dir}"/>
|
||||
<delete dir="${dist.dir}"/>
|
||||
</target>
|
||||
<target name="clean" depends="init">
|
||||
<delete dir="${work.dir}"/>
|
||||
<delete dir="${dist.dir}"/>
|
||||
</target>
|
||||
|
||||
<target name="file-exists" unless="file.exists">
|
||||
<available property="file.exists" file="${file}"/>
|
||||
</target>
|
||||
<target name="file-exists" unless="file.exists">
|
||||
<available property="file.exists" file="${file}"/>
|
||||
</target>
|
||||
|
||||
<target name="debug" depends="init">
|
||||
<!-- For debugging and testing purposes -->
|
||||
</target>
|
||||
<target name="debug" depends="init">
|
||||
<!-- For debugging and testing purposes -->
|
||||
</target>
|
||||
</project>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
|
@ -39,10 +39,10 @@
|
|||
* @constructor
|
||||
*/
|
||||
var Message = function(id, pluralId) {
|
||||
this.id = id && String(id);
|
||||
this.pluralId = pluralId && String(pluralId);
|
||||
this.locations = [];
|
||||
return this;
|
||||
this.id = id && String(id);
|
||||
this.pluralId = pluralId && String(pluralId);
|
||||
this.locations = [];
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -54,11 +54,11 @@ var Message = function(id, pluralId) {
|
|||
* @type String
|
||||
*/
|
||||
Message.getKey = function(id, pluralId) {
|
||||
if (id && pluralId) {
|
||||
return id + pluralId;
|
||||
} else {
|
||||
return id;
|
||||
}
|
||||
if (id && pluralId) {
|
||||
return id + pluralId;
|
||||
} else {
|
||||
return id;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -71,28 +71,28 @@ Message.getKey = function(id, pluralId) {
|
|||
* @type String
|
||||
*/
|
||||
Message.formatId = function(str, wrap) {
|
||||
var escapeQuotes = function(s) {
|
||||
return s.replace(/(^|[^\\])"/g, '$1\\"');
|
||||
};
|
||||
var escapeQuotes = function(s) {
|
||||
return s.replace(/(^|[^\\])"/g, '$1\\"');
|
||||
};
|
||||
|
||||
var len = 80;
|
||||
var buf = new java.lang.StringBuffer();
|
||||
if (wrap == true && str.length > len) {
|
||||
buf.append('""\n');
|
||||
var offset = 0;
|
||||
while (offset < str.length) {
|
||||
buf.append('"');
|
||||
buf.append(escapeQuotes(str.substring(offset, offset += len)));
|
||||
buf.append('"');
|
||||
buf.append("\n");
|
||||
}
|
||||
return buf.toString();
|
||||
} else {
|
||||
var len = 80;
|
||||
var buf = new java.lang.StringBuffer();
|
||||
if (wrap == true && str.length > len) {
|
||||
buf.append('""\n');
|
||||
var offset = 0;
|
||||
while (offset < str.length) {
|
||||
buf.append('"');
|
||||
buf.append(escapeQuotes(str));
|
||||
buf.append('"\n');
|
||||
}
|
||||
return buf.toString();
|
||||
buf.append(escapeQuotes(str.substring(offset, offset += len)));
|
||||
buf.append('"');
|
||||
buf.append("\n");
|
||||
}
|
||||
return buf.toString();
|
||||
} else {
|
||||
buf.append('"');
|
||||
buf.append(escapeQuotes(str));
|
||||
buf.append('"\n');
|
||||
}
|
||||
return buf.toString();
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -103,7 +103,7 @@ Message.formatId = function(str, wrap) {
|
|||
* was found at
|
||||
*/
|
||||
Message.prototype.addLocation = function(filePath, lineNum) {
|
||||
this.locations.push(filePath + ":" + lineNum);
|
||||
this.locations.push(filePath + ":" + lineNum);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -113,34 +113,34 @@ Message.prototype.addLocation = function(filePath, lineNum) {
|
|||
* to write into
|
||||
*/
|
||||
Message.prototype.write = function(buf) {
|
||||
for (var i=0;i<this.locations.length;i++) {
|
||||
buf.append("#: ");
|
||||
buf.append(this.locations[i]);
|
||||
buf.append("\n");
|
||||
}
|
||||
if (this.id.indexOf("{") > -1
|
||||
|| (this.pluralId != null && this.pluralId.indexOf("{") > -1)) {
|
||||
buf.append("#, java-format\n");
|
||||
}
|
||||
buf.append('msgid ');
|
||||
buf.append(Message.formatId(this.id));
|
||||
if (this.pluralId != null) {
|
||||
buf.append('msgid_plural ');
|
||||
buf.append(Message.formatId(this.pluralId));
|
||||
buf.append('msgstr[0] ""\nmsgstr[1] ""\n')
|
||||
} else {
|
||||
buf.append('msgstr ""\n')
|
||||
}
|
||||
buf.append("\n");
|
||||
return;
|
||||
for (var i=0;i<this.locations.length;i++) {
|
||||
buf.append("#: ");
|
||||
buf.append(this.locations[i]);
|
||||
buf.append("\n");
|
||||
}
|
||||
if (this.id.indexOf("{") > -1
|
||||
|| (this.pluralId != null && this.pluralId.indexOf("{") > -1)) {
|
||||
buf.append("#, java-format\n");
|
||||
}
|
||||
buf.append('msgid ');
|
||||
buf.append(Message.formatId(this.id));
|
||||
if (this.pluralId != null) {
|
||||
buf.append('msgid_plural ');
|
||||
buf.append(Message.formatId(this.pluralId));
|
||||
buf.append('msgstr[0] ""\nmsgstr[1] ""\n')
|
||||
} else {
|
||||
buf.append('msgstr ""\n')
|
||||
}
|
||||
buf.append("\n");
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
var MessageParser = function() {
|
||||
this.messages = {};
|
||||
return this;
|
||||
this.messages = {};
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -150,11 +150,11 @@ var MessageParser = function() {
|
|||
* @type Object
|
||||
*/
|
||||
MessageParser.FUNCTION_NAMES = {
|
||||
"_": true,
|
||||
"gettext": true,
|
||||
"ngettext": true,
|
||||
"markgettext": true,
|
||||
"cgettext": true
|
||||
"_": true,
|
||||
"gettext": true,
|
||||
"ngettext": true,
|
||||
"markgettext": true,
|
||||
"cgettext": true
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -198,7 +198,7 @@ MessageParser.REGEX_PARAM = /([\w]*)\s*=\s*["'](.*?)["']\s*(?=\w+=|$)/gm;
|
|||
* @type Number
|
||||
*/
|
||||
MessageParser.getLineNum = function(str, idx) {
|
||||
return str.substring(0, idx).split(/.*(?:\r\n|\n\r|\r|\n)/).length;
|
||||
return str.substring(0, idx).split(/.*(?:\r\n|\n\r|\r|\n)/).length;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -209,36 +209,36 @@ MessageParser.getLineNum = function(str, idx) {
|
|||
* @param {String} encoding The encoding to use
|
||||
*/
|
||||
MessageParser.prototype.parse = function(file, encoding) {
|
||||
if (file.isDirectory()) {
|
||||
var list = file.list();
|
||||
for (var i=0;i<list.length;i++) {
|
||||
this.parse(new java.io.File(file, list[i]), encoding);
|
||||
if (file.isDirectory()) {
|
||||
var list = file.list();
|
||||
for (var i=0;i<list.length;i++) {
|
||||
this.parse(new java.io.File(file, list[i]), encoding);
|
||||
}
|
||||
} else {
|
||||
var fName, dotIdx;
|
||||
fName = file.getName();
|
||||
if ((dotIdx = fName.lastIndexOf(".")) > -1) {
|
||||
switch (String(fName.substring(dotIdx+1))) {
|
||||
case "skin":
|
||||
print("Parsing skin file " + file.getCanonicalPath() + "...");
|
||||
this.parseSkinFile(file, encoding);
|
||||
break;
|
||||
case "hac":
|
||||
case "js":
|
||||
print("Parsing function file " + file.getCanonicalPath() + "...");
|
||||
this.parseFunctionFile(file, encoding);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
var fName, dotIdx;
|
||||
fName = file.getName();
|
||||
if ((dotIdx = fName.lastIndexOf(".")) > -1) {
|
||||
switch (String(fName.substring(dotIdx+1))) {
|
||||
case "skin":
|
||||
print("Parsing skin file " + file.getCanonicalPath() + "...");
|
||||
this.parseSkinFile(file, encoding);
|
||||
break;
|
||||
case "hac":
|
||||
case "js":
|
||||
print("Parsing function file " + file.getCanonicalPath() + "...");
|
||||
this.parseFunctionFile(file, encoding);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
||||
/** @ignore */
|
||||
MessageParser.prototype.toString = function() {
|
||||
return "[Jala Message Parser]";
|
||||
return "[Jala Message Parser]";
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -248,65 +248,65 @@ MessageParser.prototype.toString = function() {
|
|||
* @param {String} encoding The encoding to use
|
||||
*/
|
||||
MessageParser.prototype.parseFunctionFile = function(file, encoding) {
|
||||
var fis = new java.io.FileInputStream(file);
|
||||
var isr = new java.io.InputStreamReader(fis, encoding || "UTF-8");
|
||||
var reader = new java.io.BufferedReader(isr);
|
||||
var tokenizer = new java.io.StreamTokenizer(reader);
|
||||
var messages = [], stack = [];
|
||||
var c;
|
||||
while ((c = tokenizer.nextToken()) != java.io.StreamTokenizer.TT_EOF) {
|
||||
switch (c) {
|
||||
case java.io.StreamTokenizer.TT_WORD:
|
||||
if (MessageParser.FUNCTION_NAMES[tokenizer.sval] == true) {
|
||||
stack.push({name: tokenizer.sval, lineNr: tokenizer.lineno()});
|
||||
} else if (stack.length > 0) {
|
||||
// it's something else than a string argument inside a gettext method call
|
||||
// so finalize the argument parsing here as we aren't interested in that
|
||||
messages.push(stack.pop());
|
||||
}
|
||||
break;
|
||||
case java.io.StreamTokenizer.TT_NUMBER:
|
||||
break;
|
||||
default:
|
||||
if (stack.length > 0) {
|
||||
if ("\u0028".charCodeAt(0) == c) {
|
||||
// start of arguments (an opening bracket)
|
||||
stack[stack.length-1].args = [];
|
||||
} else if ("\u0029".charCodeAt(0) == c) {
|
||||
// end of arguments (a closing bracket)
|
||||
messages.push(stack.pop());
|
||||
} else if ("\u0022".charCodeAt(0) == c || "\u0027".charCodeAt(0) == c) {
|
||||
// a quoted string argument
|
||||
stack[stack.length-1].args.push(tokenizer.sval);
|
||||
}
|
||||
}
|
||||
break;
|
||||
var fis = new java.io.FileInputStream(file);
|
||||
var isr = new java.io.InputStreamReader(fis, encoding || "UTF-8");
|
||||
var reader = new java.io.BufferedReader(isr);
|
||||
var tokenizer = new java.io.StreamTokenizer(reader);
|
||||
var messages = [], stack = [];
|
||||
var c;
|
||||
while ((c = tokenizer.nextToken()) != java.io.StreamTokenizer.TT_EOF) {
|
||||
switch (c) {
|
||||
case java.io.StreamTokenizer.TT_WORD:
|
||||
if (MessageParser.FUNCTION_NAMES[tokenizer.sval] == true) {
|
||||
stack.push({name: tokenizer.sval, lineNr: tokenizer.lineno()});
|
||||
} else if (stack.length > 0) {
|
||||
// it's something else than a string argument inside a gettext method call
|
||||
// so finalize the argument parsing here as we aren't interested in that
|
||||
messages.push(stack.pop());
|
||||
}
|
||||
break;
|
||||
case java.io.StreamTokenizer.TT_NUMBER:
|
||||
break;
|
||||
default:
|
||||
if (stack.length > 0) {
|
||||
if ("\u0028".charCodeAt(0) == c) {
|
||||
// start of arguments (an opening bracket)
|
||||
stack[stack.length-1].args = [];
|
||||
} else if ("\u0029".charCodeAt(0) == c) {
|
||||
// end of arguments (a closing bracket)
|
||||
messages.push(stack.pop());
|
||||
} else if ("\u0022".charCodeAt(0) == c || "\u0027".charCodeAt(0) == c) {
|
||||
// a quoted string argument
|
||||
stack[stack.length-1].args.push(tokenizer.sval);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (messages.length > 0) {
|
||||
var msgParam, key, msg;
|
||||
for (var i=0;i<messages.length;i++) {
|
||||
msgParam = messages[i];
|
||||
if (msgParam.args && msgParam.args.length > 0) {
|
||||
if (msgParam.name === "cgettext" || msgParam.name === "markgettext") {
|
||||
msgParam.args[0] = cgettext.getKey(msgParam.args[0], msgParam.args[1]);
|
||||
delete msgParam.args[1];
|
||||
}
|
||||
key = Message.getKey(msgParam.args[0]);
|
||||
if (!(msg = this.messages[key])) {
|
||||
this.messages[key] = msg = new Message(msgParam.args[0], msgParam.args[1]);
|
||||
}
|
||||
if (!msg.pluralId && msgParam.args.length > 1) {
|
||||
msg.pluralId = msgParam.args[1];
|
||||
}
|
||||
msg.addLocation(file.getCanonicalPath(), msgParam.lineNr);
|
||||
}
|
||||
}
|
||||
if (messages.length > 0) {
|
||||
var msgParam, key, msg;
|
||||
for (var i=0;i<messages.length;i++) {
|
||||
msgParam = messages[i];
|
||||
if (msgParam.args && msgParam.args.length > 0) {
|
||||
if (msgParam.name === "cgettext" || msgParam.name === "markgettext") {
|
||||
msgParam.args[0] = cgettext.getKey(msgParam.args[0], msgParam.args[1]);
|
||||
delete msgParam.args[1];
|
||||
}
|
||||
key = Message.getKey(msgParam.args[0]);
|
||||
if (!(msg = this.messages[key])) {
|
||||
this.messages[key] = msg = new Message(msgParam.args[0], msgParam.args[1]);
|
||||
}
|
||||
if (!msg.pluralId && msgParam.args.length > 1) {
|
||||
msg.pluralId = msgParam.args[1];
|
||||
}
|
||||
msg.addLocation(file.getCanonicalPath(), msgParam.lineNr);
|
||||
}
|
||||
}
|
||||
}
|
||||
fis.close();
|
||||
isr.close();
|
||||
reader.close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
fis.close();
|
||||
isr.close();
|
||||
reader.close();
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -324,72 +324,72 @@ MessageParser.prototype.parseFunctionFile = function(file, encoding) {
|
|||
* @param {String} encoding The encoding to use
|
||||
*/
|
||||
MessageParser.prototype.parseSkinFile = function(file, encoding) {
|
||||
var self = this;
|
||||
var source = readFile(file.getAbsolutePath(), encoding || "UTF-8");
|
||||
var self = this;
|
||||
var source = readFile(file.getAbsolutePath(), encoding || "UTF-8");
|
||||
|
||||
var checkNestedMacros = function(iterator) {
|
||||
var macros = [];
|
||||
while (iterator.hasNext()) {
|
||||
macro = iterator.next();
|
||||
if (macro && macro.constructor !== String) {
|
||||
macros.push(macro);
|
||||
}
|
||||
var checkNestedMacros = function(iterator) {
|
||||
var macros = [];
|
||||
while (iterator.hasNext()) {
|
||||
macro = iterator.next();
|
||||
if (macro && macro.constructor !== String) {
|
||||
macros.push(macro);
|
||||
}
|
||||
processMacros(macros);
|
||||
}
|
||||
}
|
||||
processMacros(macros);
|
||||
}
|
||||
|
||||
var processMacros = function(macros) {
|
||||
var re = gettext_macro.REGEX;
|
||||
var id, pluralId, name, args, param, key, msg;
|
||||
for each (var macro in macros) {
|
||||
id = pluralId = null;
|
||||
name = macro.getName();
|
||||
param = macro.getNamedParams();
|
||||
if (param) {
|
||||
checkNestedMacros(param.values().iterator());
|
||||
if (name === MessageParser.MACRO_NAME) {
|
||||
id = param.get("text");
|
||||
pluralId = param.get("plural");
|
||||
} else if (param.containsKey("message") === MessageParser.ATTRIBUTE_NAME) {
|
||||
id = param.get("message");
|
||||
pluralId = param.get("plural");
|
||||
}
|
||||
}
|
||||
args = macro.getPositionalParams();
|
||||
if (args) {
|
||||
checkNestedMacros(args.iterator());
|
||||
if (name === "gettext" || name === "markgettext") {
|
||||
id = cgettext.getKey(args.get(0), param && param.get("context"));
|
||||
} else if (name === "ngettext") {
|
||||
id = args.get(0);
|
||||
pluralId = args.get(1);
|
||||
}
|
||||
}
|
||||
if (id != null) {
|
||||
if (id.constructor !== String) {
|
||||
continue;
|
||||
}
|
||||
// create new Message instance or update the existing one
|
||||
id = id.replace(re, String.SPACE);
|
||||
pluralId && (pluralId = pluralId.replace(re, String.SPACE));
|
||||
key = Message.getKey(id);
|
||||
if (!(msg = self.messages[key])) {
|
||||
self.messages[key] = msg = new Message(id, pluralId, file.getCanonicalPath());
|
||||
}
|
||||
msg.addLocation(file.getCanonicalPath(), MessageParser.getLineNum(source, macro.start));
|
||||
}
|
||||
var processMacros = function(macros) {
|
||||
var re = gettext_macro.REGEX;
|
||||
var id, pluralId, name, args, param, key, msg;
|
||||
for each (var macro in macros) {
|
||||
id = pluralId = null;
|
||||
name = macro.getName();
|
||||
param = macro.getNamedParams();
|
||||
if (param) {
|
||||
checkNestedMacros(param.values().iterator());
|
||||
if (name === MessageParser.MACRO_NAME) {
|
||||
id = param.get("text");
|
||||
pluralId = param.get("plural");
|
||||
} else if (param.containsKey("message") === MessageParser.ATTRIBUTE_NAME) {
|
||||
id = param.get("message");
|
||||
pluralId = param.get("plural");
|
||||
}
|
||||
}
|
||||
}
|
||||
args = macro.getPositionalParams();
|
||||
if (args) {
|
||||
checkNestedMacros(args.iterator());
|
||||
if (name === "gettext" || name === "markgettext") {
|
||||
id = cgettext.getKey(args.get(0), param && param.get("context"));
|
||||
} else if (name === "ngettext") {
|
||||
id = args.get(0);
|
||||
pluralId = args.get(1);
|
||||
}
|
||||
}
|
||||
if (id != null) {
|
||||
if (id.constructor !== String) {
|
||||
continue;
|
||||
}
|
||||
// create new Message instance or update the existing one
|
||||
id = id.replace(re, String.SPACE);
|
||||
pluralId && (pluralId = pluralId.replace(re, String.SPACE));
|
||||
key = Message.getKey(id);
|
||||
if (!(msg = self.messages[key])) {
|
||||
self.messages[key] = msg = new Message(id, pluralId, file.getCanonicalPath());
|
||||
}
|
||||
msg.addLocation(file.getCanonicalPath(), MessageParser.getLineNum(source, macro.start));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var skin = createSkin(source);
|
||||
if (skin.hasMainskin()) {
|
||||
processMacros(skin.getMacros());
|
||||
}
|
||||
for each (var name in skin.getSubskinNames()) {
|
||||
var subskin = skin.getSubskin(name);
|
||||
processMacros(subskin.getMacros());
|
||||
}
|
||||
return;
|
||||
var skin = createSkin(source);
|
||||
if (skin.hasMainskin()) {
|
||||
processMacros(skin.getMacros());
|
||||
}
|
||||
for each (var name in skin.getSubskinNames()) {
|
||||
var subskin = skin.getSubskin(name);
|
||||
processMacros(subskin.getMacros());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -399,58 +399,58 @@ MessageParser.prototype.parseSkinFile = function(file, encoding) {
|
|||
* @see http://drupal.org/node/17564
|
||||
*/
|
||||
MessageParser.prototype.getPotString = function() {
|
||||
var date = new Date;
|
||||
var buf = new java.lang.StringBuffer();
|
||||
buf.append('#\n');
|
||||
buf.append('# The Antville Project\n');
|
||||
buf.append('# http://code.google.com/p/antville\n');
|
||||
buf.append('#\n');
|
||||
buf.append('# Copyright 2001-' + date.getFullYear() + ' by The Antville People\n');
|
||||
buf.append('#\n');
|
||||
buf.append("# Licensed under the Apache License, Version 2.0 (the ``License''\n");
|
||||
buf.append('# you may not use this file except in compliance with the License.\n');
|
||||
buf.append('# You may obtain a copy of the License at\n');
|
||||
buf.append('#\n');
|
||||
buf.append('# http://www.apache.org/licenses/LICENSE-2.0\n');
|
||||
buf.append('#\n');
|
||||
buf.append('# Unless required by applicable law or agreed to in writing, software\n');
|
||||
buf.append("# distributed under the License is distributed on an ``AS IS'' BASIS,\n");
|
||||
buf.append('# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n');
|
||||
buf.append('# See the License for the specific language governing permissions and\n');
|
||||
buf.append('# limitations under the License.\n');
|
||||
buf.append('#\n');
|
||||
buf.append('# $Revision$\n');
|
||||
buf.append('# $Author$\n');
|
||||
buf.append('# $Date$\n');
|
||||
buf.append('# $URL$\n');
|
||||
buf.append('#\n');
|
||||
buf.append('#, fuzzy\n');
|
||||
buf.append('msgid ""\n');
|
||||
buf.append('msgstr ""\n');
|
||||
buf.append('"Project-Id-Version: Antville-' + Root.VERSION + '\\n"\n');
|
||||
buf.append('"Report-Msgid-Bugs-To: mail@antville.org\\n"\n');
|
||||
var sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mmZ");
|
||||
buf.append('"POT-Creation-Date: ' + sdf.format(new java.util.Date()) + '\\n"\n');
|
||||
buf.append('"PO-Revision-Date: ' + sdf.format(new java.util.Date()) + '\\n"\n');
|
||||
//buf.append('"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"\n');
|
||||
buf.append('"Language-Team: The Antville People <mail@antville.org>\\n"\n');
|
||||
buf.append('"MIME-Version: 1.0\\n"\n');
|
||||
buf.append('"Content-Type: text/plain; charset=utf-8\\n"\n');
|
||||
buf.append('"Content-Transfer-Encoding: 8bit\\n"\n');
|
||||
buf.append('"Plural-Forms: nplurals=2; plural=(n != 1);\\n"\n');
|
||||
buf.append('\n');
|
||||
var date = new Date;
|
||||
var buf = new java.lang.StringBuffer();
|
||||
buf.append('#\n');
|
||||
buf.append('# The Antville Project\n');
|
||||
buf.append('# http://code.google.com/p/antville\n');
|
||||
buf.append('#\n');
|
||||
buf.append('# Copyright 2001-' + date.getFullYear() + ' by The Antville People\n');
|
||||
buf.append('#\n');
|
||||
buf.append("# Licensed under the Apache License, Version 2.0 (the ``License''\n");
|
||||
buf.append('# you may not use this file except in compliance with the License.\n');
|
||||
buf.append('# You may obtain a copy of the License at\n');
|
||||
buf.append('#\n');
|
||||
buf.append('# http://www.apache.org/licenses/LICENSE-2.0\n');
|
||||
buf.append('#\n');
|
||||
buf.append('# Unless required by applicable law or agreed to in writing, software\n');
|
||||
buf.append("# distributed under the License is distributed on an ``AS IS'' BASIS,\n");
|
||||
buf.append('# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n');
|
||||
buf.append('# See the License for the specific language governing permissions and\n');
|
||||
buf.append('# limitations under the License.\n');
|
||||
buf.append('#\n');
|
||||
buf.append('# $Revision$\n');
|
||||
buf.append('# $Author$\n');
|
||||
buf.append('# $Date$\n');
|
||||
buf.append('# $URL$\n');
|
||||
buf.append('#\n');
|
||||
buf.append('#, fuzzy\n');
|
||||
buf.append('msgid ""\n');
|
||||
buf.append('msgstr ""\n');
|
||||
buf.append('"Project-Id-Version: Antville-' + Root.VERSION + '\\n"\n');
|
||||
buf.append('"Report-Msgid-Bugs-To: mail@antville.org\\n"\n');
|
||||
var sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mmZ");
|
||||
buf.append('"POT-Creation-Date: ' + sdf.format(new java.util.Date()) + '\\n"\n');
|
||||
buf.append('"PO-Revision-Date: ' + sdf.format(new java.util.Date()) + '\\n"\n');
|
||||
//buf.append('"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"\n');
|
||||
buf.append('"Language-Team: The Antville People <mail@antville.org>\\n"\n');
|
||||
buf.append('"MIME-Version: 1.0\\n"\n');
|
||||
buf.append('"Content-Type: text/plain; charset=utf-8\\n"\n');
|
||||
buf.append('"Content-Transfer-Encoding: 8bit\\n"\n');
|
||||
buf.append('"Plural-Forms: nplurals=2; plural=(n != 1);\\n"\n');
|
||||
buf.append('\n');
|
||||
|
||||
// sort all messages by their singular key
|
||||
var keys = [];
|
||||
for (var i in this.messages) {
|
||||
keys[keys.length] = this.messages[i].id;
|
||||
}
|
||||
keys.sort();
|
||||
// add all the messages
|
||||
for (var i=0;i<keys.length;i++) {
|
||||
this.messages[keys[i]].write(buf);
|
||||
}
|
||||
return new java.lang.String(buf);
|
||||
// sort all messages by their singular key
|
||||
var keys = [];
|
||||
for (var i in this.messages) {
|
||||
keys[keys.length] = this.messages[i].id;
|
||||
}
|
||||
keys.sort();
|
||||
// add all the messages
|
||||
for (var i=0;i<keys.length;i++) {
|
||||
this.messages[keys[i]].write(buf);
|
||||
}
|
||||
return new java.lang.String(buf);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -458,10 +458,10 @@ MessageParser.prototype.getPotString = function() {
|
|||
* @param {java.io.File} file The file to write to
|
||||
*/
|
||||
MessageParser.prototype.writeToFile = function(file) {
|
||||
var writer = new java.io.FileWriter(file);
|
||||
writer.write(new java.lang.String(this.getPotString().getBytes("UTF-8")));
|
||||
writer.close();
|
||||
return;
|
||||
var writer = new java.io.FileWriter(file);
|
||||
writer.write(new java.lang.String(this.getPotString().getBytes("UTF-8")));
|
||||
writer.close();
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -471,24 +471,24 @@ var toParse = [];
|
|||
var arg, outFile, file, fileEncoding;
|
||||
|
||||
for (var i=0;i<arguments.length;i++) {
|
||||
arg = arguments[i];
|
||||
if (arg.indexOf("-o") === 0 && i < arguments.length -1) {
|
||||
outFile = new java.io.File(arguments[i += 1]);
|
||||
} else if (arg.indexOf("-e") === 0 && i < arguments.length -1) {
|
||||
fileEncoding = arguments[i += 1];
|
||||
} else {
|
||||
// add argument to list of files and directories to parse
|
||||
toParse.push(new java.io.File(arg));
|
||||
}
|
||||
arg = arguments[i];
|
||||
if (arg.indexOf("-o") === 0 && i < arguments.length -1) {
|
||||
outFile = new java.io.File(arguments[i += 1]);
|
||||
} else if (arg.indexOf("-e") === 0 && i < arguments.length -1) {
|
||||
fileEncoding = arguments[i += 1];
|
||||
} else {
|
||||
// add argument to list of files and directories to parse
|
||||
toParse.push(new java.io.File(arg));
|
||||
}
|
||||
}
|
||||
|
||||
// start parsing
|
||||
var parser = new MessageParser();
|
||||
for (var i=0;i<toParse.length;i++) {
|
||||
parser.parse(toParse[i], fileEncoding);
|
||||
parser.parse(toParse[i], fileEncoding);
|
||||
}
|
||||
if (outFile != null) {
|
||||
parser.writeToFile(outFile);
|
||||
parser.writeToFile(outFile);
|
||||
} else {
|
||||
print(parser.getPotString());
|
||||
print(parser.getPotString());
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
|
@ -49,24 +49,24 @@
|
|||
* @constructor
|
||||
*/
|
||||
var PoParser = function(namespace) {
|
||||
/**
|
||||
* An array containing the parsed messages
|
||||
* @type Array
|
||||
*/
|
||||
this.messages = [];
|
||||
/**
|
||||
* An array containing the parsed messages
|
||||
* @type Array
|
||||
*/
|
||||
this.messages = [];
|
||||
|
||||
/**
|
||||
* The locale key string (eg. "de_AT") of the .po file
|
||||
* @type String
|
||||
*/
|
||||
this.localeKey = null;
|
||||
/**
|
||||
* The locale key string (eg. "de_AT") of the .po file
|
||||
* @type String
|
||||
*/
|
||||
this.localeKey = null;
|
||||
|
||||
/**
|
||||
* The namespace (optional) where to store the generated messages
|
||||
* @type String
|
||||
*/
|
||||
this.namespace = namespace;
|
||||
return this;
|
||||
/**
|
||||
* The namespace (optional) where to store the generated messages
|
||||
* @type String
|
||||
*/
|
||||
this.namespace = namespace;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -108,7 +108,7 @@ PoParser.REGEX_MSGSTR = /^\s*msgstr(?:\[(\d)\])?\s+\"(.*)\"\s*$/;
|
|||
PoParser.REGEX_DATA = /^\s*msg/;
|
||||
|
||||
PoParser.isData = function(str) {
|
||||
return PoParser.REGEX_DATA.test(str);
|
||||
return PoParser.REGEX_DATA.test(str);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -118,21 +118,21 @@ PoParser.isData = function(str) {
|
|||
* @type java.lang.String
|
||||
*/
|
||||
PoParser.readFile = function(file) {
|
||||
var inStream = new java.io.InputStreamReader(new java.io.FileInputStream(file), "UTF-8");
|
||||
var buffer = new java.lang.reflect.Array.newInstance(java.lang.Character.TYPE, 2048);
|
||||
var read = 0;
|
||||
var r = 0;
|
||||
while ((r = inStream.read(buffer, read, buffer.length - read)) > -1) {
|
||||
read += r;
|
||||
if (read == buffer.length) {
|
||||
// grow input buffer
|
||||
var newBuffer = new java.lang.reflect.Array.newInstance(java.lang.Character.TYPE, buffer.length * 2);
|
||||
java.lang.System.arraycopy(buffer, 0, newBuffer, 0, buffer.length);
|
||||
buffer = newBuffer;
|
||||
}
|
||||
}
|
||||
inStream.close();
|
||||
return new java.lang.String(buffer, 0, read);
|
||||
var inStream = new java.io.InputStreamReader(new java.io.FileInputStream(file), "UTF-8");
|
||||
var buffer = new java.lang.reflect.Array.newInstance(java.lang.Character.TYPE, 2048);
|
||||
var read = 0;
|
||||
var r = 0;
|
||||
while ((r = inStream.read(buffer, read, buffer.length - read)) > -1) {
|
||||
read += r;
|
||||
if (read == buffer.length) {
|
||||
// grow input buffer
|
||||
var newBuffer = new java.lang.reflect.Array.newInstance(java.lang.Character.TYPE, buffer.length * 2);
|
||||
java.lang.System.arraycopy(buffer, 0, newBuffer, 0, buffer.length);
|
||||
buffer = newBuffer;
|
||||
}
|
||||
}
|
||||
inStream.close();
|
||||
return new java.lang.String(buffer, 0, read);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -141,63 +141,63 @@ PoParser.readFile = function(file) {
|
|||
* @param {java.io.File} file The .po file to parse
|
||||
*/
|
||||
PoParser.prototype.parse = function(file) {
|
||||
// parse the locale key out of the file name
|
||||
var fileName = file.getName();
|
||||
if (!(this.localeKey = fileName.substring(0, fileName.indexOf(".")))) {
|
||||
throw "Invalid PO file name: " + fileName;
|
||||
}
|
||||
// parse the locale key out of the file name
|
||||
var fileName = file.getName();
|
||||
if (!(this.localeKey = fileName.substring(0, fileName.indexOf(".")))) {
|
||||
throw "Invalid PO file name: " + fileName;
|
||||
}
|
||||
|
||||
// read the PO file content and parse it into messages
|
||||
var content = PoParser.readFile(file);
|
||||
var start = new Date();
|
||||
var lines = content.split(PoParser.REGEX_LINES);
|
||||
var idx = -1;
|
||||
var line = null;
|
||||
var m, value, nr;
|
||||
var msg;
|
||||
// read the PO file content and parse it into messages
|
||||
var content = PoParser.readFile(file);
|
||||
var start = new Date();
|
||||
var lines = content.split(PoParser.REGEX_LINES);
|
||||
var idx = -1;
|
||||
var line = null;
|
||||
var m, value, nr;
|
||||
var msg;
|
||||
|
||||
var hasMoreLines = function() {
|
||||
return idx < lines.length - 1;
|
||||
};
|
||||
var hasMoreLines = function() {
|
||||
return idx < lines.length - 1;
|
||||
};
|
||||
|
||||
var nextLine = function() {
|
||||
return (line = lines[idx += 1]) != null;
|
||||
};
|
||||
var nextLine = function() {
|
||||
return (line = lines[idx += 1]) != null;
|
||||
};
|
||||
|
||||
var getContinuation = function(str) {
|
||||
var nLine;
|
||||
while ((nLine = lines[idx + 1]) != null) {
|
||||
if ((m = nLine.match(PoParser.REGEX_MSG_CONT)) != null) {
|
||||
str += m[1];
|
||||
nextLine();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
var getContinuation = function(str) {
|
||||
var nLine;
|
||||
while ((nLine = lines[idx + 1]) != null) {
|
||||
if ((m = nLine.match(PoParser.REGEX_MSG_CONT)) != null) {
|
||||
str += m[1];
|
||||
nextLine();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
while (nextLine()) {
|
||||
if ((m = line.match(PoParser.REGEX_MSGID)) != null) {
|
||||
value = getContinuation(m[1]);
|
||||
if (value) {
|
||||
msg = this.messages[this.messages.length] = new Message(value);
|
||||
}
|
||||
} else if ((m = line.match(PoParser.REGEX_MSGID_PLURAL)) != null) {
|
||||
value = getContinuation(m[1]);
|
||||
if (value && msg != null) {
|
||||
msg.pluralKey = value;
|
||||
}
|
||||
} else if ((m = line.match(PoParser.REGEX_MSGSTR)) != null) {
|
||||
nr = m[1];
|
||||
value = getContinuation(m[2]);
|
||||
if (value && msg != null) {
|
||||
nr = parseInt(nr, 10);
|
||||
msg.translations[nr || 0] = value;
|
||||
}
|
||||
while (nextLine()) {
|
||||
if ((m = line.match(PoParser.REGEX_MSGID)) != null) {
|
||||
value = getContinuation(m[1]);
|
||||
if (value) {
|
||||
msg = this.messages[this.messages.length] = new Message(value);
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else if ((m = line.match(PoParser.REGEX_MSGID_PLURAL)) != null) {
|
||||
value = getContinuation(m[1]);
|
||||
if (value && msg != null) {
|
||||
msg.pluralKey = value;
|
||||
}
|
||||
} else if ((m = line.match(PoParser.REGEX_MSGSTR)) != null) {
|
||||
nr = m[1];
|
||||
value = getContinuation(m[2]);
|
||||
if (value && msg != null) {
|
||||
nr = parseInt(nr, 10);
|
||||
msg.translations[nr || 0] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -207,44 +207,44 @@ PoParser.prototype.parse = function(file) {
|
|||
* file should be saved
|
||||
*/
|
||||
PoParser.prototype.writeToFile = function(output) {
|
||||
var buf = new java.lang.StringBuffer();
|
||||
// write header
|
||||
buf.append('/**\n');
|
||||
buf.append(' * Instantiate the messages namespace if it\'s not already existing\n');
|
||||
buf.append(' */\n');
|
||||
var buf = new java.lang.StringBuffer();
|
||||
// write header
|
||||
buf.append('/**\n');
|
||||
buf.append(' * Instantiate the messages namespace if it\'s not already existing\n');
|
||||
buf.append(' */\n');
|
||||
var objPath = "";
|
||||
if (this.namespace) {
|
||||
objPath += this.namespace;
|
||||
buf.append('if (!global.' + objPath + ') {\n');
|
||||
buf.append(' global.' + objPath + ' = {};\n');
|
||||
buf.append('}\n');
|
||||
objPath += ".";
|
||||
}
|
||||
objPath += "messages";
|
||||
buf.append('if (!global.' + objPath + ') {\n');
|
||||
buf.append(' global.' + objPath + ' = {};\n');
|
||||
buf.append('}\n\n');
|
||||
if (this.namespace) {
|
||||
objPath += this.namespace;
|
||||
buf.append('if (!global.' + objPath + ') {\n');
|
||||
buf.append(' global.' + objPath + ' = {};\n');
|
||||
buf.append('}\n');
|
||||
objPath += ".";
|
||||
}
|
||||
objPath += "messages";
|
||||
buf.append('if (!global.' + objPath + ') {\n');
|
||||
buf.append(' global.' + objPath + ' = {};\n');
|
||||
buf.append('}\n\n');
|
||||
|
||||
buf.append('/**\n');
|
||||
buf.append(' * Messages for locale "' + this.localeKey + '"\n');
|
||||
buf.append(' */\n');
|
||||
var fname = objPath + "." + this.localeKey + ".js";
|
||||
objPath += "['" + this.localeKey + "']";
|
||||
buf.append('global.' + objPath + ' = {\n');
|
||||
// write messages
|
||||
for (var i=0;i<this.messages.length; i++) {
|
||||
this.messages[i].write(buf);
|
||||
}
|
||||
// write footer
|
||||
buf.append('};\n');
|
||||
buf.append('/**\n');
|
||||
buf.append(' * Messages for locale "' + this.localeKey + '"\n');
|
||||
buf.append(' */\n');
|
||||
var fname = objPath + "." + this.localeKey + ".js";
|
||||
objPath += "['" + this.localeKey + "']";
|
||||
buf.append('global.' + objPath + ' = {\n');
|
||||
// write messages
|
||||
for (var i=0;i<this.messages.length; i++) {
|
||||
this.messages[i].write(buf);
|
||||
}
|
||||
// write footer
|
||||
buf.append('};\n');
|
||||
|
||||
// write the message catalog into the outFile
|
||||
var file = new java.io.File(output, fname);
|
||||
var writer = new java.io.FileWriter(file);
|
||||
writer.write(new java.lang.String(buf.toString().getBytes("UTF-8")));
|
||||
writer.close();
|
||||
print("generated messages file " + file.getAbsolutePath());
|
||||
return;
|
||||
// write the message catalog into the outFile
|
||||
var file = new java.io.File(output, fname);
|
||||
var writer = new java.io.FileWriter(file);
|
||||
writer.write(new java.lang.String(buf.toString().getBytes("UTF-8")));
|
||||
writer.close();
|
||||
print("generated messages file " + file.getAbsolutePath());
|
||||
return;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -255,10 +255,10 @@ PoParser.prototype.writeToFile = function(output) {
|
|||
* @constructor
|
||||
*/
|
||||
var Message = function(singularKey) {
|
||||
this.singularKey = singularKey;
|
||||
this.pluralKey = null;
|
||||
this.translations = [];
|
||||
return this;
|
||||
this.singularKey = singularKey;
|
||||
this.pluralKey = null;
|
||||
this.translations = [];
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -267,37 +267,37 @@ var Message = function(singularKey) {
|
|||
* string to
|
||||
*/
|
||||
Message.prototype.write = function(buf) {
|
||||
var writeLine = function(key, value) {
|
||||
buf.append(' "');
|
||||
buf.append(key);
|
||||
buf.append('": "');
|
||||
if (value !== null && value !== undefined) {
|
||||
buf.append(value);
|
||||
}
|
||||
buf.append('",\n');
|
||||
};
|
||||
var writeLine = function(key, value) {
|
||||
buf.append(' "');
|
||||
buf.append(key);
|
||||
buf.append('": "');
|
||||
if (value !== null && value !== undefined) {
|
||||
buf.append(value);
|
||||
}
|
||||
buf.append('",\n');
|
||||
};
|
||||
|
||||
if (this.singularKey != null) {
|
||||
writeLine(this.singularKey, this.translations[0]);
|
||||
if (this.pluralKey != null) {
|
||||
writeLine(this.pluralKey, this.translations[1]);
|
||||
}
|
||||
}
|
||||
return;
|
||||
if (this.singularKey != null) {
|
||||
writeLine(this.singularKey, this.translations[0]);
|
||||
if (this.pluralKey != null) {
|
||||
writeLine(this.pluralKey, this.translations[1]);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main script body
|
||||
*/
|
||||
if (arguments.length < 2) {
|
||||
print("Usage:");
|
||||
print("PoParser.js <input> <output> [namespace]");
|
||||
print("<input>: Either a single .po file or a directory containing .po files");
|
||||
print("<output>: The directory where the generated messages files should be stored");
|
||||
print("[namespace]: An optional global namespace where the messages should be");
|
||||
print(" stored (eg. a namespace like 'jala' will lead to messages");
|
||||
print(" stored in global.jala.messages by their locale.");
|
||||
quit();
|
||||
print("Usage:");
|
||||
print("PoParser.js <input> <output> [namespace]");
|
||||
print("<input>: Either a single .po file or a directory containing .po files");
|
||||
print("<output>: The directory where the generated messages files should be stored");
|
||||
print("[namespace]: An optional global namespace where the messages should be");
|
||||
print(" stored (eg. a namespace like 'jala' will lead to messages");
|
||||
print(" stored in global.jala.messages by their locale.");
|
||||
quit();
|
||||
}
|
||||
|
||||
var input = new java.io.File(arguments[0]);
|
||||
|
@ -306,31 +306,31 @@ var namespace = arguments[2];
|
|||
|
||||
// check if the output destination is a directory
|
||||
if (output.isFile()) {
|
||||
print("Invalid arguments: the output destination must be a directory.");
|
||||
quit();
|
||||
print("Invalid arguments: the output destination must be a directory.");
|
||||
quit();
|
||||
}
|
||||
|
||||
if (namespace && namespace.indexOf(".") != -1) {
|
||||
print("Invalid arguments: Please don't specify complex object paths, as this");
|
||||
print("would corrupt the messages file.");
|
||||
quit();
|
||||
print("Invalid arguments: Please don't specify complex object paths, as this");
|
||||
print("would corrupt the messages file.");
|
||||
quit();
|
||||
}
|
||||
|
||||
// parse the PO file(s) and create the message catalog files
|
||||
var parser;
|
||||
if (input.isDirectory()) {
|
||||
var files = input.listFiles();
|
||||
var file;
|
||||
for (var i=0;i<files.length;i++) {
|
||||
file = files[i];
|
||||
if (file.getName().endsWith(".po")) {
|
||||
parser = new PoParser(namespace);
|
||||
parser.parse(file);
|
||||
parser.writeToFile(output);
|
||||
}
|
||||
}
|
||||
var files = input.listFiles();
|
||||
var file;
|
||||
for (var i=0;i<files.length;i++) {
|
||||
file = files[i];
|
||||
if (file.getName().endsWith(".po")) {
|
||||
parser = new PoParser(namespace);
|
||||
parser.parse(file);
|
||||
parser.writeToFile(output);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
parser = new PoParser(namespace);
|
||||
parser.parse(input);
|
||||
parser.writeToFile(output);
|
||||
parser = new PoParser(namespace);
|
||||
parser.parse(input);
|
||||
parser.writeToFile(output);
|
||||
}
|
||||
|
|
|
@ -2,74 +2,74 @@ CodeMirror.defineMode("helma-skin", function(config, parserConfig) {
|
|||
|
||||
//config settings
|
||||
var macroStartRegex = parserConfig.macroStartRegex || /^<%/i,
|
||||
macroEndRegex = parserConfig.macroEndRegex || /^%>/i;
|
||||
macroEndRegex = parserConfig.macroEndRegex || /^%>/i;
|
||||
|
||||
//inner modes
|
||||
var htmlMixedMode;
|
||||
var macroMode = {
|
||||
startState: function() {
|
||||
return {}
|
||||
},
|
||||
token: function(stream, state) {
|
||||
var c = stream.next();
|
||||
return 'helma-macro';
|
||||
}
|
||||
}
|
||||
startState: function() {
|
||||
return {}
|
||||
},
|
||||
token: function(stream, state) {
|
||||
var c = stream.next();
|
||||
return 'helma-macro';
|
||||
}
|
||||
}
|
||||
|
||||
//tokenizer when in html mode
|
||||
function htmlDispatch(stream, state) {
|
||||
if (stream.match(macroStartRegex, false)) {
|
||||
state.token=macroDispatch;
|
||||
return macroMode.token(stream, state.macroState);
|
||||
}
|
||||
else
|
||||
return htmlMixedMode.token(stream, state.htmlState);
|
||||
}
|
||||
if (stream.match(macroStartRegex, false)) {
|
||||
state.token=macroDispatch;
|
||||
return macroMode.token(stream, state.macroState);
|
||||
}
|
||||
else
|
||||
return htmlMixedMode.token(stream, state.htmlState);
|
||||
}
|
||||
|
||||
//tokenizer when in macro mode
|
||||
function macroDispatch(stream, state) {
|
||||
if (stream.match(macroEndRegex, false)) {
|
||||
state.token=htmlDispatch;
|
||||
return htmlMixedMode.token(stream, state.htmlState);
|
||||
}
|
||||
else{
|
||||
var style = macroMode.token(stream, state.macroState);
|
||||
return style;
|
||||
}
|
||||
if (stream.match(macroEndRegex, false)) {
|
||||
state.token=htmlDispatch;
|
||||
return htmlMixedMode.token(stream, state.htmlState);
|
||||
}
|
||||
else{
|
||||
var style = macroMode.token(stream, state.macroState);
|
||||
return style;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
startState: function() {
|
||||
htmlMixedMode = htmlMixedMode || CodeMirror.getMode(config, "htmlmixed");
|
||||
return {
|
||||
token : parserConfig.startOpen ? macroDispatch : htmlDispatch,
|
||||
htmlState : htmlMixedMode.startState(),
|
||||
macroState : macroMode.startState()
|
||||
}
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
return state.token(stream, state);
|
||||
},
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
if (state.token == htmlDispatch)
|
||||
return htmlMixedMode.indent(state.htmlState, textAfter);
|
||||
else
|
||||
return macroMode.indent(state.macroState, textAfter);
|
||||
},
|
||||
|
||||
copyState: function(state) {
|
||||
return {
|
||||
token : state.token,
|
||||
htmlState : CodeMirror.copyState(htmlMixedMode, state.htmlState),
|
||||
macroState : CodeMirror.copyState(macroMode, state.macroState)
|
||||
startState: function() {
|
||||
htmlMixedMode = htmlMixedMode || CodeMirror.getMode(config, "htmlmixed");
|
||||
return {
|
||||
token : parserConfig.startOpen ? macroDispatch : htmlDispatch,
|
||||
htmlState : htmlMixedMode.startState(),
|
||||
macroState : macroMode.startState()
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
return state.token(stream, state);
|
||||
},
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
if (state.token == htmlDispatch)
|
||||
return htmlMixedMode.indent(state.htmlState, textAfter);
|
||||
else
|
||||
return macroMode.indent(state.macroState, textAfter);
|
||||
},
|
||||
|
||||
copyState: function(state) {
|
||||
return {
|
||||
token : state.token,
|
||||
htmlState : CodeMirror.copyState(htmlMixedMode, state.htmlState),
|
||||
macroState : CodeMirror.copyState(macroMode, state.macroState)
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
electricChars: "/{}:"
|
||||
electricChars: "/{}:"
|
||||
}
|
||||
}, "htmlmixed");
|
||||
|
||||
|
|
|
@ -1,33 +1,33 @@
|
|||
/** Called automatically by JsDoc Toolkit. */
|
||||
function publish(symbolSet) {
|
||||
publish.conf = { // trailing slash expected for dirs
|
||||
ext: ".html",
|
||||
outDir: JSDOC.opt.d || SYS.pwd+"../out/jsdoc/",
|
||||
ext: ".html",
|
||||
outDir: JSDOC.opt.d || SYS.pwd+"../out/jsdoc/",
|
||||
templatesDir: JSDOC.opt.t || SYS.pwd+"../templates/jsdoc/",
|
||||
staticDir: "static/",
|
||||
staticDir: "static/",
|
||||
symbolsDir: "symbols/",
|
||||
srcDir: "symbols/src/",
|
||||
cssDir: "css/",
|
||||
fontsDir: "css/fonts/",
|
||||
jsDir: "javascript/",
|
||||
srcDir: "symbols/src/",
|
||||
cssDir: "css/",
|
||||
fontsDir: "css/fonts/",
|
||||
jsDir: "javascript/",
|
||||
templateName: "Codeview",
|
||||
templateVersion: "1.2",
|
||||
templateLink: "http://www.thebrightlines.com/2010/05/06/new-template-for-jsdoctoolkit-codeview/"
|
||||
};
|
||||
|
||||
|
||||
// is source output is suppressed, just display the links to the source file
|
||||
if (JSDOC.opt.s && defined(Link) && Link.prototype._makeSrcLink) {
|
||||
Link.prototype._makeSrcLink = function(srcFilePath) {
|
||||
return "<"+srcFilePath+">";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// create the folders and subfolders to hold the output
|
||||
IO.mkPath((publish.conf.outDir+publish.conf.cssDir));
|
||||
IO.mkPath((publish.conf.outDir+publish.conf.fontsDir));
|
||||
IO.mkPath((publish.conf.outDir+publish.conf.jsDir));
|
||||
IO.mkPath((publish.conf.outDir+"symbols/src").split("/"));
|
||||
|
||||
|
||||
// used to allow Link to check the details of things being linked to
|
||||
Link.symbolSet = symbolSet;
|
||||
|
||||
|
@ -39,15 +39,15 @@ function publish(symbolSet) {
|
|||
print("Couldn't create the required templates: "+e);
|
||||
quit();
|
||||
}
|
||||
|
||||
|
||||
// some utility filters
|
||||
function hasNoParent($) {return ($.memberOf == "")}
|
||||
function isaFile($) {return ($.is("FILE"))}
|
||||
function isaClass($) {return (($.is("CONSTRUCTOR") || $.isNamespace) && ($.alias != "_global_" || !JSDOC.opt.D.noGlobal))}
|
||||
|
||||
|
||||
// get an array version of the symbolset, useful for filtering
|
||||
var symbols = symbolSet.toArray();
|
||||
|
||||
|
||||
// create the hilited source code files
|
||||
var files = JSDOC.opt.srcFiles;
|
||||
for (var i = 0, l = files.length; i < l; i++) {
|
||||
|
@ -55,74 +55,74 @@ function publish(symbolSet) {
|
|||
var srcDir = publish.conf.outDir + publish.conf.srcDir;
|
||||
makeSrcFile(file, srcDir);
|
||||
}
|
||||
|
||||
|
||||
// get a list of all the classes in the symbolset
|
||||
publish.classes = symbols.filter(isaClass).sort(makeSortby("alias"));
|
||||
|
||||
|
||||
// create a filemap in which outfiles must be to be named uniquely, ignoring case
|
||||
if (JSDOC.opt.u) {
|
||||
var filemapCounts = {};
|
||||
Link.filemap = {};
|
||||
for (var i = 0, l = publish.classes.length; i < l; i++) {
|
||||
var lcAlias = publish.classes[i].alias.toLowerCase();
|
||||
|
||||
|
||||
if (!filemapCounts[lcAlias]) filemapCounts[lcAlias] = 1;
|
||||
else filemapCounts[lcAlias]++;
|
||||
|
||||
Link.filemap[publish.classes[i].alias] =
|
||||
|
||||
Link.filemap[publish.classes[i].alias] =
|
||||
(filemapCounts[lcAlias] > 1)?
|
||||
lcAlias+"_"+filemapCounts[lcAlias] : lcAlias;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// create each of the class pages
|
||||
for (var i = 0, l = publish.classes.length; i < l; i++) {
|
||||
var symbol = publish.classes[i];
|
||||
|
||||
symbol.events = symbol.getEvents(); // 1 order matters
|
||||
|
||||
symbol.events = symbol.getEvents(); // 1 order matters
|
||||
symbol.methods = symbol.getMethods(); // 2
|
||||
|
||||
|
||||
var output = "";
|
||||
output = classTemplate.process(symbol);
|
||||
|
||||
|
||||
IO.saveFile(publish.conf.outDir+publish.conf.symbolsDir, ((JSDOC.opt.u)? Link.filemap[symbol.alias] : symbol.alias) + publish.conf.ext, output);
|
||||
}
|
||||
|
||||
|
||||
// create the class index page
|
||||
try {
|
||||
var classesindexTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"allclasses.tmpl");
|
||||
}
|
||||
catch(e) { print(e.message); quit(); }
|
||||
|
||||
|
||||
var classesIndex = classesindexTemplate.process(publish.classes);
|
||||
IO.saveFile(publish.conf.outDir, (JSDOC.opt.D.index=="files"?"allclasses":"index")+publish.conf.ext, classesIndex);
|
||||
classesindexTemplate = classesIndex = classes = null;
|
||||
|
||||
|
||||
// create the file index page
|
||||
try {
|
||||
var fileindexTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"allfiles.tmpl");
|
||||
}
|
||||
catch(e) { print(e.message); quit(); }
|
||||
|
||||
|
||||
var documentedFiles = symbols.filter(isaFile); // files that have file-level docs
|
||||
var allFiles = []; // not all files have file-level docs, but we need to list every one
|
||||
|
||||
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
allFiles.push(new JSDOC.Symbol(files[i], [], "FILE", new JSDOC.DocComment("/** */")));
|
||||
}
|
||||
|
||||
|
||||
for (var i = 0; i < documentedFiles.length; i++) {
|
||||
var offset = files.indexOf(documentedFiles[i].alias);
|
||||
allFiles[offset] = documentedFiles[i];
|
||||
}
|
||||
|
||||
|
||||
allFiles = allFiles.sort(makeSortby("name"));
|
||||
|
||||
// output the file index page
|
||||
var filesIndex = fileindexTemplate.process(allFiles);
|
||||
IO.saveFile(publish.conf.outDir, (JSDOC.opt.D.index=="files"?"index":"files")+publish.conf.ext, filesIndex);
|
||||
fileindexTemplate = filesIndex = files = null;
|
||||
|
||||
|
||||
// copy static files
|
||||
IO.copyFile(publish.conf.templatesDir+"/"+publish.conf.cssDir+"all.css", publish.conf.outDir+"/"+publish.conf.cssDir);
|
||||
IO.copyFile(publish.conf.templatesDir+"/"+publish.conf.cssDir+"screen.css", publish.conf.outDir+"/"+publish.conf.cssDir);
|
||||
|
@ -181,14 +181,14 @@ function include(path) {
|
|||
/** Turn a raw source file into a code-hilited page in the docs. */
|
||||
function makeSrcFile(path, srcDir, name) {
|
||||
if (JSDOC.opt.s) return;
|
||||
|
||||
|
||||
if (!name) {
|
||||
name = path.replace(/\.\.?[\\\/]/g, "").replace(/[\\\/]/g, "_");
|
||||
name = name.replace(/\:/g, "_");
|
||||
}
|
||||
|
||||
|
||||
var src = {path: path, name:name, charset: IO.encoding, hilited: ""};
|
||||
|
||||
|
||||
if (defined(JSDOC.PluginManager)) {
|
||||
JSDOC.PluginManager.run("onPublishSrc", src);
|
||||
}
|
||||
|
@ -219,18 +219,18 @@ function makeSignature(params) {
|
|||
|
||||
/** Find symbol {@link ...} strings in text and turn into html links */
|
||||
function resolveLinks(str, from) {
|
||||
str = str.replace(/\{@link ([^}]+)\}/gi,
|
||||
function(match, symbolName) {
|
||||
str = str.replace(/\{@link ([^}]+)\}/gi,
|
||||
function(match, symbolName) {
|
||||
symbolName = symbolName.trim();
|
||||
var index = symbolName.indexOf(' ');
|
||||
if (index > 0) {
|
||||
var label = symbolName.substring(index + 1);
|
||||
symbolName = symbolName.substring(0, index);
|
||||
return new Link().toSymbol(symbolName).withText(label);
|
||||
var label = symbolName.substring(index + 1);
|
||||
symbolName = symbolName.substring(0, index);
|
||||
return new Link().toSymbol(symbolName).withText(label);
|
||||
} else {
|
||||
return new Link().toSymbol(symbolName);
|
||||
return new Link().toSymbol(symbolName);
|
||||
}
|
||||
}
|
||||
);
|
||||
return str;
|
||||
}
|
||||
);
|
||||
return str;
|
||||
}
|
|
@ -1,23 +1,23 @@
|
|||
/** Called automatically by JsDoc Toolkit. */
|
||||
function publish(symbolSet) {
|
||||
publish.conf = { // trailing slash expected for dirs
|
||||
ext: ".html",
|
||||
outDir: JSDOC.opt.d || SYS.pwd+"../out/jsdoc/",
|
||||
ext: ".html",
|
||||
outDir: JSDOC.opt.d || SYS.pwd+"../out/jsdoc/",
|
||||
templatesDir: JSDOC.opt.t || SYS.pwd+"../templates/jsdoc/",
|
||||
symbolsDir: "symbols/",
|
||||
srcDir: "symbols/src/"
|
||||
srcDir: "symbols/src/"
|
||||
};
|
||||
|
||||
|
||||
// is source output is suppressed, just display the links to the source file
|
||||
if (JSDOC.opt.s && defined(Link) && Link.prototype._makeSrcLink) {
|
||||
Link.prototype._makeSrcLink = function(srcFilePath) {
|
||||
return "<"+srcFilePath+">";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// create the folders and subfolders to hold the output
|
||||
IO.mkPath((publish.conf.outDir+"symbols/src").split("/"));
|
||||
|
||||
|
||||
// used to allow Link to check the details of things being linked to
|
||||
Link.symbolSet = symbolSet;
|
||||
|
||||
|
@ -30,15 +30,15 @@ function publish(symbolSet) {
|
|||
print("Couldn't create the required templates: "+e);
|
||||
quit();
|
||||
}
|
||||
|
||||
|
||||
// some ustility filters
|
||||
function hasNoParent($) {return ($.memberOf == "")}
|
||||
function isaFile($) {return ($.is("FILE"))}
|
||||
function isaClass($) {return ($.is("CONSTRUCTOR") || $.isNamespace)}
|
||||
|
||||
|
||||
// get an array version of the symbolset, useful for filtering
|
||||
var symbols = symbolSet.toArray();
|
||||
|
||||
|
||||
// create the hilited source code files
|
||||
var files = JSDOC.opt.srcFiles;
|
||||
for (var i = 0, l = files.length; i < l; i++) {
|
||||
|
@ -46,76 +46,76 @@ function publish(symbolSet) {
|
|||
var srcDir = publish.conf.outDir + "symbols/src/";
|
||||
makeSrcFile(file, srcDir);
|
||||
}
|
||||
|
||||
|
||||
// get a list of all the classes in the symbolset
|
||||
var classes = symbols.filter(isaClass).sort(makeSortby("alias"));
|
||||
|
||||
|
||||
// create a filemap in which outfiles must be to be named uniquely, ignoring case
|
||||
if (JSDOC.opt.u) {
|
||||
var filemapCounts = {};
|
||||
Link.filemap = {};
|
||||
for (var i = 0, l = classes.length; i < l; i++) {
|
||||
var lcAlias = classes[i].alias.toLowerCase();
|
||||
|
||||
|
||||
if (!filemapCounts[lcAlias]) filemapCounts[lcAlias] = 1;
|
||||
else filemapCounts[lcAlias]++;
|
||||
|
||||
Link.filemap[classes[i].alias] =
|
||||
|
||||
Link.filemap[classes[i].alias] =
|
||||
(filemapCounts[lcAlias] > 1)?
|
||||
lcAlias+"_"+filemapCounts[lcAlias] : lcAlias;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// create a class index, displayed in the left-hand column of every class page
|
||||
Link.base = "../";
|
||||
publish.classesIndex = classesTemplate.process(classes); // kept in memory
|
||||
|
||||
|
||||
// create each of the class pages
|
||||
for (var i = 0, l = classes.length; i < l; i++) {
|
||||
var symbol = classes[i];
|
||||
|
||||
symbol.events = symbol.getEvents(); // 1 order matters
|
||||
|
||||
symbol.events = symbol.getEvents(); // 1 order matters
|
||||
symbol.methods = symbol.getMethods(); // 2
|
||||
|
||||
|
||||
Link.currentSymbol= symbol;
|
||||
var output = "";
|
||||
output = classTemplate.process(symbol);
|
||||
|
||||
|
||||
IO.saveFile(publish.conf.outDir+"symbols/", ((JSDOC.opt.u)? Link.filemap[symbol.alias] : symbol.alias) + publish.conf.ext, output);
|
||||
}
|
||||
|
||||
|
||||
// regenerate the index with different relative links, used in the index pages
|
||||
Link.base = "";
|
||||
publish.classesIndex = classesTemplate.process(classes);
|
||||
|
||||
|
||||
// create the class index page
|
||||
try {
|
||||
var classesindexTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"index.tmpl");
|
||||
}
|
||||
catch(e) { print(e.message); quit(); }
|
||||
|
||||
|
||||
var classesIndex = classesindexTemplate.process(classes);
|
||||
IO.saveFile(publish.conf.outDir, "index"+publish.conf.ext, classesIndex);
|
||||
classesindexTemplate = classesIndex = classes = null;
|
||||
|
||||
|
||||
// create the file index page
|
||||
try {
|
||||
var fileindexTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"allfiles.tmpl");
|
||||
}
|
||||
catch(e) { print(e.message); quit(); }
|
||||
|
||||
|
||||
var documentedFiles = symbols.filter(isaFile); // files that have file-level docs
|
||||
var allFiles = []; // not all files have file-level docs, but we need to list every one
|
||||
|
||||
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
allFiles.push(new JSDOC.Symbol(files[i], [], "FILE", new JSDOC.DocComment("/** */")));
|
||||
}
|
||||
|
||||
|
||||
for (var i = 0; i < documentedFiles.length; i++) {
|
||||
var offset = files.indexOf(documentedFiles[i].alias);
|
||||
allFiles[offset] = documentedFiles[i];
|
||||
}
|
||||
|
||||
|
||||
allFiles = allFiles.sort(makeSortby("name"));
|
||||
|
||||
// output the file index page
|
||||
|
@ -153,14 +153,14 @@ function include(path) {
|
|||
/** Turn a raw source file into a code-hilited page in the docs. */
|
||||
function makeSrcFile(path, srcDir, name) {
|
||||
if (JSDOC.opt.s) return;
|
||||
|
||||
|
||||
if (!name) {
|
||||
name = path.replace(/\.\.?[\\\/]/g, "").replace(/[\\\/]/g, "_");
|
||||
name = name.replace(/\:/g, "_");
|
||||
}
|
||||
|
||||
|
||||
var src = {path: path, name:name, charset: IO.encoding, hilited: ""};
|
||||
|
||||
|
||||
if (defined(JSDOC.PluginManager)) {
|
||||
JSDOC.PluginManager.run("onPublishSrc", src);
|
||||
}
|
||||
|
@ -196,6 +196,6 @@ function resolveLinks(str, from) {
|
|||
return new Link().toSymbol(symbolName);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
return str;
|
||||
}
|
||||
|
|
1106
code/Admin/Admin.js
1106
code/Admin/Admin.js
File diff suppressed because it is too large
Load diff
|
@ -10,7 +10,7 @@
|
|||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
|
@ -37,21 +37,21 @@ Api.blogger = {};
|
|||
* @param {String} content
|
||||
*/
|
||||
Api.blogger._getContentParts = function(content) {
|
||||
content && (content = content.trim());
|
||||
content || (content = String.EMPTY);
|
||||
var result = {};
|
||||
if (!content.startsWith("<title>")) {
|
||||
content && (content = content.trim());
|
||||
content || (content = String.EMPTY);
|
||||
var result = {};
|
||||
if (!content.startsWith("<title>")) {
|
||||
result.text = content;
|
||||
} else {
|
||||
var pos = content.lastIndexOf("</title>");
|
||||
if (pos > 0) {
|
||||
result.title = content.substring(7, pos);
|
||||
result.text = content.substring (pos + 8);
|
||||
} else {
|
||||
result.text = content;
|
||||
} else {
|
||||
var pos = content.lastIndexOf("</title>");
|
||||
if (pos > 0) {
|
||||
result.title = content.substring(7, pos);
|
||||
result.text = content.substring (pos + 8);
|
||||
} else {
|
||||
result.text = content;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,15 +63,15 @@ Api.blogger._getContentParts = function(content) {
|
|||
* @returns {Object} Properties: userid, nickname and url
|
||||
*/
|
||||
Api.blogger.getUserInfo = function(appKey, name, password) {
|
||||
var user = User.getByName(name);
|
||||
if (!user) {
|
||||
throw Error("User " + name + " does not exist on this server");
|
||||
}
|
||||
return {
|
||||
userid: name,
|
||||
nickname: name,
|
||||
url: user.url
|
||||
}
|
||||
var user = User.getByName(name);
|
||||
if (!user) {
|
||||
throw Error("User " + name + " does not exist on this server");
|
||||
}
|
||||
return {
|
||||
userid: name,
|
||||
nickname: name,
|
||||
url: user.url
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,20 +83,20 @@ Api.blogger.getUserInfo = function(appKey, name, password) {
|
|||
* url
|
||||
*/
|
||||
Api.blogger.getUsersBlogs = function(appKey, name, password) {
|
||||
var user = Api.getUser(name, password);
|
||||
var result = [];
|
||||
user.forEach(function() {
|
||||
Api.constrain(this.site, user);
|
||||
if (this.site.stories.getPermission("create")) {
|
||||
result.push({
|
||||
blogid: this.site.name,
|
||||
blogName: this.site.title,
|
||||
url: this.site.href()
|
||||
});
|
||||
}
|
||||
return;
|
||||
});
|
||||
return result;
|
||||
var user = Api.getUser(name, password);
|
||||
var result = [];
|
||||
user.forEach(function() {
|
||||
Api.constrain(this.site, user);
|
||||
if (this.site.stories.getPermission("create")) {
|
||||
result.push({
|
||||
blogid: this.site.name,
|
||||
blogName: this.site.title,
|
||||
url: this.site.href()
|
||||
});
|
||||
}
|
||||
return;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -111,28 +111,28 @@ Api.blogger.getUsersBlogs = function(appKey, name, password) {
|
|||
* dateCreated and content
|
||||
*/
|
||||
Api.blogger.getRecentPosts = function(appKey, id, name, password, limit) {
|
||||
var site = Api.getSite(id);
|
||||
var user = Api.getUser(name, password);
|
||||
var site = Api.getSite(id);
|
||||
var user = Api.getUser(name, password);
|
||||
|
||||
Api.constrain(site, user);
|
||||
if (!site.stories.getPermission("main")) {
|
||||
throw Error("Permission denied for user " + user.name +
|
||||
" to get recent posts of site " + site.name);
|
||||
}
|
||||
Api.constrain(site, user);
|
||||
if (!site.stories.getPermission("main")) {
|
||||
throw Error("Permission denied for user " + user.name +
|
||||
" to get recent posts of site " + site.name);
|
||||
}
|
||||
|
||||
var result = [];
|
||||
var stories = res.handlers.membership.stories;
|
||||
var max = Math.min(stories.size(), Number(limit) || Infinity, 20);
|
||||
for each (var story in stories.list(0, max)) {
|
||||
result.push({
|
||||
postid: story._id,
|
||||
userid: story.creator.name,
|
||||
dateCreated: story.created,
|
||||
content: story.title ? "<title>" + story.title +
|
||||
"</title>" + story.text : story.text
|
||||
});
|
||||
}
|
||||
return result;
|
||||
var result = [];
|
||||
var stories = res.handlers.membership.stories;
|
||||
var max = Math.min(stories.size(), Number(limit) || Infinity, 20);
|
||||
for each (var story in stories.list(0, max)) {
|
||||
result.push({
|
||||
postid: story._id,
|
||||
userid: story.creator.name,
|
||||
dateCreated: story.created,
|
||||
content: story.title ? "<title>" + story.title +
|
||||
"</title>" + story.text : story.text
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -145,22 +145,22 @@ Api.blogger.getRecentPosts = function(appKey, id, name, password, limit) {
|
|||
* @returns {Object} Properties: content, userid, postid, dateCreated
|
||||
*/
|
||||
Api.blogger.getPost = function(appKey, id, name, password) {
|
||||
var story = Api.getStory(id);
|
||||
var user = Api.getUser(name, password);
|
||||
var story = Api.getStory(id);
|
||||
var user = Api.getUser(name, password);
|
||||
|
||||
Api.constrain(story.site, user);
|
||||
if (!story.getPermission("main")) {
|
||||
throw Error("Permission denied for user " + name +
|
||||
" to get post #" + id);
|
||||
}
|
||||
Api.constrain(story.site, user);
|
||||
if (!story.getPermission("main")) {
|
||||
throw Error("Permission denied for user " + name +
|
||||
" to get post #" + id);
|
||||
}
|
||||
|
||||
return {
|
||||
content: story.title ? html.elementAsString("title", story.title) +
|
||||
story.text : story.text,
|
||||
userid: story.creator.name,
|
||||
postid: story._id,
|
||||
dateCreated: story.created
|
||||
}
|
||||
return {
|
||||
content: story.title ? html.elementAsString("title", story.title) +
|
||||
story.text : story.text,
|
||||
userid: story.creator.name,
|
||||
postid: story._id,
|
||||
dateCreated: story.created
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -175,25 +175,25 @@ Api.blogger.getPost = function(appKey, id, name, password) {
|
|||
* @returns {Number} The ID of the new story
|
||||
*/
|
||||
Api.blogger.newPost = function(appKey, id, name, password, content, publish) {
|
||||
var site = Api.getSite(id);
|
||||
var user = Api.getUser(name, password);
|
||||
var site = Api.getSite(id);
|
||||
var user = Api.getUser(name, password);
|
||||
|
||||
Api.constrain(site, user);
|
||||
if (!site.stories.getPermission("create")) {
|
||||
throw Error("Permission denied for user " + user.name +
|
||||
" to add a post to site " + site.name);
|
||||
}
|
||||
Api.constrain(site, user);
|
||||
if (!site.stories.getPermission("create")) {
|
||||
throw Error("Permission denied for user " + user.name +
|
||||
" to add a post to site " + site.name);
|
||||
}
|
||||
|
||||
var parts = Api.blogger._getContentParts(content);
|
||||
var parts = Api.blogger._getContentParts(content);
|
||||
|
||||
var story = Story.add({
|
||||
title: parts.title,
|
||||
text: parts.text,
|
||||
status: publish ? Story.PUBLIC : Story.CLOSED,
|
||||
mode: Story.FEATURED
|
||||
}, site, user);
|
||||
var story = Story.add({
|
||||
title: parts.title,
|
||||
text: parts.text,
|
||||
status: publish ? Story.PUBLIC : Story.CLOSED,
|
||||
mode: Story.FEATURED
|
||||
}, site, user);
|
||||
|
||||
return story._id;
|
||||
return story._id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -208,24 +208,24 @@ Api.blogger.newPost = function(appKey, id, name, password, content, publish) {
|
|||
* @returns {Boolean} Always true
|
||||
*/
|
||||
Api.blogger.editPost = function(appkey, id, name, password, content, publish) {
|
||||
var story = Api.getStory(id);
|
||||
var user = Api.getUser(name, password);
|
||||
var story = Api.getStory(id);
|
||||
var user = Api.getUser(name, password);
|
||||
|
||||
Api.constrain(story.site, user);
|
||||
if (!story.getPermission("edit")) {
|
||||
throw Error("Permission denied for user " + name +
|
||||
" to edit post #" + id);
|
||||
}
|
||||
Api.constrain(story.site, user);
|
||||
if (!story.getPermission("edit")) {
|
||||
throw Error("Permission denied for user " + name +
|
||||
" to edit post #" + id);
|
||||
}
|
||||
|
||||
var parts = Api.blogger._getContentParts(content);
|
||||
story.update({
|
||||
title: parts.title,
|
||||
text: parts.text,
|
||||
status: publish ? Story.PUBLIC : Story.CLOSED,
|
||||
modifier: user,
|
||||
modified: new Date
|
||||
});
|
||||
return true;
|
||||
var parts = Api.blogger._getContentParts(content);
|
||||
story.update({
|
||||
title: parts.title,
|
||||
text: parts.text,
|
||||
status: publish ? Story.PUBLIC : Story.CLOSED,
|
||||
modifier: user,
|
||||
modified: new Date
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -238,15 +238,15 @@ Api.blogger.editPost = function(appkey, id, name, password, content, publish) {
|
|||
* @returns {Boolean} Always true
|
||||
*/
|
||||
Api.blogger.deletePost = function(appKey, id, name, password) {
|
||||
var story = Api.getStory(id);
|
||||
var user = Api.getUser(name, password);
|
||||
var story = Api.getStory(id);
|
||||
var user = Api.getUser(name, password);
|
||||
|
||||
Api.constrain(story.site, user);
|
||||
if (!story.getPermission("delete")) {
|
||||
throw Error("Permission denied for user " + name +
|
||||
" to delete story #" + id);
|
||||
}
|
||||
Api.constrain(story.site, user);
|
||||
if (!story.getPermission("delete")) {
|
||||
throw Error("Permission denied for user " + name +
|
||||
" to delete story #" + id);
|
||||
}
|
||||
|
||||
Story.remove.call(story);
|
||||
return true;
|
||||
Story.remove.call(story);
|
||||
return true;
|
||||
}
|
||||
|
|
136
code/Api/Api.js
136
code/Api/Api.js
|
@ -8,7 +8,7 @@
|
|||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
|
@ -32,9 +32,9 @@
|
|||
* @param {User} user
|
||||
*/
|
||||
Api.constrain = function(site, user) {
|
||||
res.handlers.site = site;
|
||||
res.handlers.membership = Membership.getByName(user.name);
|
||||
return;
|
||||
res.handlers.site = site;
|
||||
res.handlers.membership = Membership.getByName(user.name);
|
||||
return;
|
||||
}
|
||||
|
||||
/** @ignore */
|
||||
|
@ -49,16 +49,16 @@ Api.dispatch = function() {
|
|||
* @returns {User}
|
||||
*/
|
||||
Api.getUser = function(name, password) {
|
||||
var user = User.getByName(name);
|
||||
if (!user) {
|
||||
throw Error("User " + name + " does not exist on this server");
|
||||
} else if (user.hash !== String(password + user.salt).md5()) {
|
||||
throw Error("Authentication failed for user " + name);
|
||||
} else if (user.status === User.BLOCKED) {
|
||||
throw Error("The user account " + name + " is currently blocked");
|
||||
}
|
||||
session.login(user);
|
||||
return user;
|
||||
var user = User.getByName(name);
|
||||
if (!user) {
|
||||
throw Error("User " + name + " does not exist on this server");
|
||||
} else if (user.hash !== String(password + user.salt).md5()) {
|
||||
throw Error("Authentication failed for user " + name);
|
||||
} else if (user.status === User.BLOCKED) {
|
||||
throw Error("The user account " + name + " is currently blocked");
|
||||
}
|
||||
session.login(user);
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,13 +68,13 @@ Api.getUser = function(name, password) {
|
|||
* @returns {Site}
|
||||
*/
|
||||
Api.getSite = function(name) {
|
||||
var site = Site.getByName(String(name));
|
||||
if (!site) {
|
||||
throw Error("Site " + name + " does not exist on this server");
|
||||
} else if (site.status === Site.BLOCKED) {
|
||||
throw Error("The site " + name + " is blocked");
|
||||
}
|
||||
return site;
|
||||
var site = Site.getByName(String(name));
|
||||
if (!site) {
|
||||
throw Error("Site " + name + " does not exist on this server");
|
||||
} else if (site.status === Site.BLOCKED) {
|
||||
throw Error("The site " + name + " is blocked");
|
||||
}
|
||||
return site;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -84,11 +84,11 @@ Api.getSite = function(name) {
|
|||
* @returns {Story}
|
||||
*/
|
||||
Api.getStory = function(id) {
|
||||
var story = Story.getById(id);
|
||||
if (!story) {
|
||||
throw Error("Story #" + id + " does not exist on this server");
|
||||
}
|
||||
return story;
|
||||
var story = Story.getById(id);
|
||||
if (!story) {
|
||||
throw Error("Story #" + id + " does not exist on this server");
|
||||
}
|
||||
return story;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,42 +101,42 @@ Api.getStory = function(id) {
|
|||
* @returns {Boolean}
|
||||
*/
|
||||
Api.prototype.getPermission = function(){
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
Api.prototype.main_action = function() {
|
||||
res.data.title = gettext("Application Programming Interfaces");
|
||||
res.data.body = this.renderSkinAsString("$Api#main");
|
||||
res.handlers.site.renderSkin("Site#page");
|
||||
return;
|
||||
res.data.title = gettext("Application Programming Interfaces");
|
||||
res.data.body = this.renderSkinAsString("$Api#main");
|
||||
res.handlers.site.renderSkin("Site#page");
|
||||
return;
|
||||
}
|
||||
|
||||
Api.prototype.callback_action = function() {
|
||||
var ping = function(data) {
|
||||
if (data.type !== "Story" && data.type !== "Comment") {
|
||||
return;
|
||||
}
|
||||
var remote = new Remote("http://rpc.weblogs.com/RPC2");
|
||||
var call = remote.weblogUpdates.ping(data.site, data.origin);
|
||||
if (call.error || call.result.flerror) {
|
||||
app.debug("Error invoking weblogs.com ping() method for " +
|
||||
data.site + ": " + call.error || call.result.message);
|
||||
} else {
|
||||
app.debug(call.result);
|
||||
}
|
||||
var ping = function(data) {
|
||||
if (data.type !== "Story" && data.type !== "Comment") {
|
||||
return;
|
||||
};
|
||||
}
|
||||
var remote = new Remote("http://rpc.weblogs.com/RPC2");
|
||||
var call = remote.weblogUpdates.ping(data.site, data.origin);
|
||||
if (call.error || call.result.flerror) {
|
||||
app.debug("Error invoking weblogs.com ping() method for " +
|
||||
data.site + ": " + call.error || call.result.message);
|
||||
} else {
|
||||
app.debug(call.result);
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
||||
if (req.isGet()) {
|
||||
res.data.title = gettext("Default Callback Url");
|
||||
res.data.body = this.renderSkinAsString("$Api#callback",
|
||||
{name: req.action, code: ping.toString()});
|
||||
res.handlers.site.renderSkin("Site#page");
|
||||
} else if (req.isPost()) {
|
||||
app.debug("Invoked default callback with POST params: " + req.postParams);
|
||||
app.invokeAsync(this, ping, [req.postParams], 1000);
|
||||
}
|
||||
return;
|
||||
if (req.isGet()) {
|
||||
res.data.title = gettext("Default Callback Url");
|
||||
res.data.body = this.renderSkinAsString("$Api#callback",
|
||||
{name: req.action, code: ping.toString()});
|
||||
res.handlers.site.renderSkin("Site#page");
|
||||
} else if (req.isPost()) {
|
||||
app.debug("Invoked default callback with POST params: " + req.postParams);
|
||||
app.invokeAsync(this, ping, [req.postParams], 1000);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -145,18 +145,18 @@ Api.prototype.callback_action = function() {
|
|||
* @throws {Error}
|
||||
*/
|
||||
Api.prototype.main_action_xmlrpc = function(methodName) {
|
||||
if (!methodName) {
|
||||
return false;
|
||||
}
|
||||
var parts = methodName.split(".");
|
||||
var method = parts[1];
|
||||
if (method && !method.startsWith("_")) {
|
||||
var handler = Api[parts[0]];
|
||||
if (handler && handler[method]) {
|
||||
var args = Array.prototype.splice.call(arguments, 1);
|
||||
return handler[method].apply(null, args);
|
||||
}
|
||||
}
|
||||
throw Error("Method " + methodName + "() is not implemented");
|
||||
return;
|
||||
if (!methodName) {
|
||||
return false;
|
||||
}
|
||||
var parts = methodName.split(".");
|
||||
var method = parts[1];
|
||||
if (method && !method.startsWith("_")) {
|
||||
var handler = Api[parts[0]];
|
||||
if (handler && handler[method]) {
|
||||
var args = Array.prototype.splice.call(arguments, 1);
|
||||
return handler[method].apply(null, args);
|
||||
}
|
||||
}
|
||||
throw Error("Method " + methodName + "() is not implemented");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
|
@ -36,24 +36,24 @@ Api.metaWeblog = {}
|
|||
* @returns {Object}
|
||||
*/
|
||||
Api.metaWeblog._getStruct = function(story) {
|
||||
return {
|
||||
userid: story.creator.name,
|
||||
postid: story._id,
|
||||
dateCreated: story.created,
|
||||
title: story.getTitle(),
|
||||
description: story.text,
|
||||
categories: story.getTags(),
|
||||
flNotOnHomePage: story.mode === Story.HIDDEN ? true : false,
|
||||
link: story.href(),
|
||||
permaLink: story.href(),
|
||||
mt_excerpt: null, // FIXME: What are these "mt_" prefixed properties?
|
||||
mt_text_more: null,
|
||||
mt_allow_comments: story.commentMode === Story.OPEN ? 1 : 0,
|
||||
mt_allow_pings: 0,
|
||||
mt_convert_breaks: null,
|
||||
mt_keywords: null,
|
||||
postSource: story.getMetadata('postSource')
|
||||
}
|
||||
return {
|
||||
userid: story.creator.name,
|
||||
postid: story._id,
|
||||
dateCreated: story.created,
|
||||
title: story.getTitle(),
|
||||
description: story.text,
|
||||
categories: story.getTags(),
|
||||
flNotOnHomePage: story.mode === Story.HIDDEN ? true : false,
|
||||
link: story.href(),
|
||||
permaLink: story.href(),
|
||||
mt_excerpt: null, // FIXME: What are these "mt_" prefixed properties?
|
||||
mt_text_more: null,
|
||||
mt_allow_comments: story.commentMode === Story.OPEN ? 1 : 0,
|
||||
mt_allow_pings: 0,
|
||||
mt_convert_breaks: null,
|
||||
mt_keywords: null,
|
||||
postSource: story.getMetadata('postSource')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,22 +66,22 @@ Api.metaWeblog._getStruct = function(story) {
|
|||
* @returns {Object[]}
|
||||
*/
|
||||
Api.metaWeblog.getRecentPosts = function(id, name, password, limit) {
|
||||
var site = Api.getSite(id);
|
||||
var user = Api.getUser(name, password);
|
||||
var site = Api.getSite(id);
|
||||
var user = Api.getUser(name, password);
|
||||
|
||||
Api.constrain(site, user);
|
||||
if (!site.stories.getPermission("main")) {
|
||||
throw Error("Permission denied for user " + user.name +
|
||||
" to get recent posts from site " + site.name);
|
||||
}
|
||||
Api.constrain(site, user);
|
||||
if (!site.stories.getPermission("main")) {
|
||||
throw Error("Permission denied for user " + user.name +
|
||||
" to get recent posts from site " + site.name);
|
||||
}
|
||||
|
||||
var result = [];
|
||||
var stories = res.handlers.membership.stories;
|
||||
var max = Math.min(stories.size(), Number(limit) || Infinity, 20);
|
||||
for each (var story in stories.list(0, max)) {
|
||||
result.push(Api.metaWeblog._getStruct(story));
|
||||
}
|
||||
return result;
|
||||
var result = [];
|
||||
var stories = res.handlers.membership.stories;
|
||||
var max = Math.min(stories.size(), Number(limit) || Infinity, 20);
|
||||
for each (var story in stories.list(0, max)) {
|
||||
result.push(Api.metaWeblog._getStruct(story));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,14 +93,14 @@ Api.metaWeblog.getRecentPosts = function(id, name, password, limit) {
|
|||
* @returns {Object}
|
||||
*/
|
||||
Api.metaWeblog.getPost = function(id, name, password) {
|
||||
var story = Api.getStory(id);
|
||||
var user = Api.getUser(name, password);
|
||||
Api.constrain(story.site, user);
|
||||
if (!story.getPermission("main")) {
|
||||
throw Error("Permission denied for user " + name +
|
||||
" to get post #" + id);
|
||||
}
|
||||
return Api.metaWeblog._getStruct(story);
|
||||
var story = Api.getStory(id);
|
||||
var user = Api.getUser(name, password);
|
||||
Api.constrain(story.site, user);
|
||||
if (!story.getPermission("main")) {
|
||||
throw Error("Permission denied for user " + name +
|
||||
" to get post #" + id);
|
||||
}
|
||||
return Api.metaWeblog._getStruct(story);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -114,26 +114,26 @@ Api.metaWeblog.getPost = function(id, name, password) {
|
|||
* @returns {Number}
|
||||
*/
|
||||
Api.metaWeblog.newPost = function(id, name, password, content, publish) {
|
||||
var site = Api.getSite(id);
|
||||
var user = Api.getUser(name, password);
|
||||
var site = Api.getSite(id);
|
||||
var user = Api.getUser(name, password);
|
||||
|
||||
Api.constrain(site, user);
|
||||
if (!site.stories.getPermission("create")) {
|
||||
throw Error("Permission denied for user " + user.name +
|
||||
" to add a post to site " + site.name);
|
||||
}
|
||||
Api.constrain(site, user);
|
||||
if (!site.stories.getPermission("create")) {
|
||||
throw Error("Permission denied for user " + user.name +
|
||||
" to add a post to site " + site.name);
|
||||
}
|
||||
|
||||
var story = Story.add({
|
||||
title: content.title,
|
||||
text: content.description,
|
||||
status: publish ? Story.PUBLIC : Story.CLOSED,
|
||||
mode: content.flNotOnHomePage ? Story.HIDDEN : Story.FEATURED,
|
||||
commentMode: content.discussions === 0 ? Story.CLOSED : Story.OPEN,
|
||||
tags: content.categories
|
||||
}, site, user);
|
||||
var story = Story.add({
|
||||
title: content.title,
|
||||
text: content.description,
|
||||
status: publish ? Story.PUBLIC : Story.CLOSED,
|
||||
mode: content.flNotOnHomePage ? Story.HIDDEN : Story.FEATURED,
|
||||
commentMode: content.discussions === 0 ? Story.CLOSED : Story.OPEN,
|
||||
tags: content.categories
|
||||
}, site, user);
|
||||
|
||||
story.setMetadata('postSource', content.postSource);
|
||||
return story._id;
|
||||
story.setMetadata('postSource', content.postSource);
|
||||
return story._id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -147,27 +147,27 @@ Api.metaWeblog.newPost = function(id, name, password, content, publish) {
|
|||
* @returns {Boolean}
|
||||
*/
|
||||
Api.metaWeblog.editPost = function(id, name, password, content, publish) {
|
||||
var story = Api.getStory(id);
|
||||
var user = Api.getUser(name, password);
|
||||
var story = Api.getStory(id);
|
||||
var user = Api.getUser(name, password);
|
||||
|
||||
Api.constrain(story.site, user);
|
||||
if (!story.getPermission("edit")) {
|
||||
throw Error("Permission denied for user " + name +
|
||||
" to edit post #" + id);
|
||||
}
|
||||
Api.constrain(story.site, user);
|
||||
if (!story.getPermission("edit")) {
|
||||
throw Error("Permission denied for user " + name +
|
||||
" to edit post #" + id);
|
||||
}
|
||||
|
||||
story.update({
|
||||
title: content.title,
|
||||
text: content.description,
|
||||
status: publish ? Story.PUBLIC : Story.CLOSED,
|
||||
mode: content.flNotOnHomePage ? Story.HIDDEN : Story.FEATURED,
|
||||
commentMode: content.discussions || content.mt_allow_comments ?
|
||||
Story.OPEN : Story.CLOSED,
|
||||
tags: content.categories
|
||||
});
|
||||
story.update({
|
||||
title: content.title,
|
||||
text: content.description,
|
||||
status: publish ? Story.PUBLIC : Story.CLOSED,
|
||||
mode: content.flNotOnHomePage ? Story.HIDDEN : Story.FEATURED,
|
||||
commentMode: content.discussions || content.mt_allow_comments ?
|
||||
Story.OPEN : Story.CLOSED,
|
||||
tags: content.categories
|
||||
});
|
||||
|
||||
story.setMetadata('postSource', content.postSource);
|
||||
return true;
|
||||
story.setMetadata('postSource', content.postSource);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -179,25 +179,25 @@ Api.metaWeblog.editPost = function(id, name, password, content, publish) {
|
|||
* @returns {Object[]}
|
||||
*/
|
||||
Api.metaWeblog.getCategories = function(id, name, password) {
|
||||
var site = Api.getSite(id);
|
||||
var user = Api.getUser(name, password);
|
||||
var site = Api.getSite(id);
|
||||
var user = Api.getUser(name, password);
|
||||
|
||||
Api.constrain(site, user);
|
||||
if (!site.stories.getPermission("main")) {
|
||||
throw Error("Permission denied for user " + user.name +
|
||||
" to get categories from site " + site.name);
|
||||
}
|
||||
Api.constrain(site, user);
|
||||
if (!site.stories.getPermission("main")) {
|
||||
throw Error("Permission denied for user " + user.name +
|
||||
" to get categories from site " + site.name);
|
||||
}
|
||||
|
||||
var result = [];
|
||||
var tags = site.getTags("tags", Tags.ALL).list();
|
||||
for each (var tag in tags) {
|
||||
result.push({
|
||||
description: tag.name,
|
||||
htmlUrl: tag.href(),
|
||||
rssUrl: tag.href("rss")
|
||||
});
|
||||
}
|
||||
return result;
|
||||
var result = [];
|
||||
var tags = site.getTags("tags", Tags.ALL).list();
|
||||
for each (var tag in tags) {
|
||||
result.push({
|
||||
description: tag.name,
|
||||
htmlUrl: tag.href(),
|
||||
rssUrl: tag.href("rss")
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -210,40 +210,40 @@ Api.metaWeblog.getCategories = function(id, name, password) {
|
|||
* @returns {Object}
|
||||
*/
|
||||
Api.metaWeblog.newMediaObject = function(id, name, password, media) {
|
||||
var site = Api.getSite(id);
|
||||
var user = Api.getUser(name, password);
|
||||
var site = Api.getSite(id);
|
||||
var user = Api.getUser(name, password);
|
||||
|
||||
Api.constrain(site, user);
|
||||
Api.constrain(site, user);
|
||||
|
||||
var result = {};
|
||||
var data = {};
|
||||
if (media.type && media.type.toLowerCase().startsWith("image/")) {
|
||||
if (!site.images.getPermission("create")) {
|
||||
throw Error("Permission denied for user " + user.name +
|
||||
" to add a media object to site " + site.name);
|
||||
}
|
||||
data.file = new Packages.helma.util.MimePart(media.name,
|
||||
media.bits, media.type);
|
||||
data.file_origin = media.name;
|
||||
data.description = media.description;
|
||||
if (media.maxWidth) {
|
||||
data.maxWidth = media.maxWidth;
|
||||
}
|
||||
if (media.maxHeight) {
|
||||
data.maxHeight = media.maxHeight;
|
||||
}
|
||||
result.url = Image.add(data, site, user).getUrl();
|
||||
} else {
|
||||
if (!site.files.getPermission("create")) {
|
||||
throw Error("Permission denied for user " + user.name +
|
||||
" to add a media object to site " + site.name);
|
||||
}
|
||||
data.file = new Packages.helma.util.MimePart(media.name,
|
||||
media.bits, media.type);
|
||||
data.file_origin = media.name;
|
||||
data.description = media.description;
|
||||
result.url = File.add(data, site, user).getUrl();
|
||||
}
|
||||
var result = {};
|
||||
var data = {};
|
||||
if (media.type && media.type.toLowerCase().startsWith("image/")) {
|
||||
if (!site.images.getPermission("create")) {
|
||||
throw Error("Permission denied for user " + user.name +
|
||||
" to add a media object to site " + site.name);
|
||||
}
|
||||
data.file = new Packages.helma.util.MimePart(media.name,
|
||||
media.bits, media.type);
|
||||
data.file_origin = media.name;
|
||||
data.description = media.description;
|
||||
if (media.maxWidth) {
|
||||
data.maxWidth = media.maxWidth;
|
||||
}
|
||||
if (media.maxHeight) {
|
||||
data.maxHeight = media.maxHeight;
|
||||
}
|
||||
result.url = Image.add(data, site, user).getUrl();
|
||||
} else {
|
||||
if (!site.files.getPermission("create")) {
|
||||
throw Error("Permission denied for user " + user.name +
|
||||
" to add a media object to site " + site.name);
|
||||
}
|
||||
data.file = new Packages.helma.util.MimePart(media.name,
|
||||
media.bits, media.type);
|
||||
data.file_origin = media.name;
|
||||
data.description = media.description;
|
||||
result.url = File.add(data, site, user).getUrl();
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
|
@ -41,27 +41,27 @@ Api.mt = {};
|
|||
* @returns {Object[]}
|
||||
*/
|
||||
Api.mt.getRecentPostTitles = function(id, name, password, limit) {
|
||||
var site = Api.getSite(id);
|
||||
var user = Api.getUser(name, password);
|
||||
var site = Api.getSite(id);
|
||||
var user = Api.getUser(name, password);
|
||||
|
||||
Api.constrain(site, user);
|
||||
if (!site.stories.getPermission("main")) {
|
||||
throw Error("Permission denied for user " + user.name +
|
||||
" to get recent post titles from site " + site.name);
|
||||
}
|
||||
Api.constrain(site, user);
|
||||
if (!site.stories.getPermission("main")) {
|
||||
throw Error("Permission denied for user " + user.name +
|
||||
" to get recent post titles from site " + site.name);
|
||||
}
|
||||
|
||||
var result = [];
|
||||
var stories = res.handlers.membership.stories;
|
||||
var max = Math.min(stories.size(), Number(limit) || Infinity, 20);
|
||||
for each (var story in stories.list(0, max)) {
|
||||
result.push({
|
||||
postid: story._id,
|
||||
username: story.creator.name,
|
||||
dateCreated: story.created,
|
||||
title: story.getTitle()
|
||||
});
|
||||
}
|
||||
return result;
|
||||
var result = [];
|
||||
var stories = res.handlers.membership.stories;
|
||||
var max = Math.min(stories.size(), Number(limit) || Infinity, 20);
|
||||
for each (var story in stories.list(0, max)) {
|
||||
result.push({
|
||||
postid: story._id,
|
||||
username: story.creator.name,
|
||||
dateCreated: story.created,
|
||||
title: story.getTitle()
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -73,24 +73,24 @@ Api.mt.getRecentPostTitles = function(id, name, password, limit) {
|
|||
* @returns {Object[]}
|
||||
*/
|
||||
Api.mt.getCategoryList = function(id, name, password) {
|
||||
var site = Api.getSite(id);
|
||||
var user = Api.getUser(name, password);
|
||||
var site = Api.getSite(id);
|
||||
var user = Api.getUser(name, password);
|
||||
|
||||
Api.constrain(site, user);
|
||||
if (!site.stories.getPermission("main")) {
|
||||
throw Error("Permission denied for user " + user.name +
|
||||
" to access site " + site.name);
|
||||
}
|
||||
Api.constrain(site, user);
|
||||
if (!site.stories.getPermission("main")) {
|
||||
throw Error("Permission denied for user " + user.name +
|
||||
" to access site " + site.name);
|
||||
}
|
||||
|
||||
var result = [];
|
||||
var tags = site.getTags("tags", Tags.ALL).list();
|
||||
for each (var tag in tags) {
|
||||
result.push({
|
||||
categoryId: tag.name, // FIXME: tag._id,
|
||||
categoryName: tag.name
|
||||
});
|
||||
}
|
||||
return result;
|
||||
var result = [];
|
||||
var tags = site.getTags("tags", Tags.ALL).list();
|
||||
for each (var tag in tags) {
|
||||
result.push({
|
||||
categoryId: tag.name, // FIXME: tag._id,
|
||||
categoryName: tag.name
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -102,24 +102,24 @@ Api.mt.getCategoryList = function(id, name, password) {
|
|||
* @returns {Object[]}
|
||||
*/
|
||||
Api.mt.getPostCategories = function(id, name, password) {
|
||||
var story = Api.getStory(id);
|
||||
var user = Api.getUser(name, password);
|
||||
var story = Api.getStory(id);
|
||||
var user = Api.getUser(name, password);
|
||||
|
||||
Api.constrain(story.site, user);
|
||||
if (!story.getPermission("main")) {
|
||||
throw Error("Permission denied for user " + name +
|
||||
" to access story #" + id);
|
||||
}
|
||||
Api.constrain(story.site, user);
|
||||
if (!story.getPermission("main")) {
|
||||
throw Error("Permission denied for user " + name +
|
||||
" to access story #" + id);
|
||||
}
|
||||
|
||||
var result = [];
|
||||
for each (var tag in story.getTags()) {
|
||||
result.push({
|
||||
categoryId: tag,
|
||||
categoryName: tag,
|
||||
isPrimary: true
|
||||
});
|
||||
}
|
||||
return result;
|
||||
var result = [];
|
||||
for each (var tag in story.getTags()) {
|
||||
result.push({
|
||||
categoryId: tag,
|
||||
categoryName: tag,
|
||||
isPrimary: true
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// FIXME: How do I post a new story?
|
||||
|
@ -132,17 +132,17 @@ Api.mt.getPostCategories = function(id, name, password) {
|
|||
* @returns {Boolean}
|
||||
*/
|
||||
Api.mt.publishPost = function(id, name, password) {
|
||||
var story = Api.getStory(id);
|
||||
var user = Api.getUser(name, password);
|
||||
var story = Api.getStory(id);
|
||||
var user = Api.getUser(name, password);
|
||||
|
||||
Api.constrain(story.site, user);
|
||||
if (!story.getPermission("edit")) {
|
||||
throw Error("Permission denied for user " + name +
|
||||
" to edit story #" + id);
|
||||
}
|
||||
Api.constrain(story.site, user);
|
||||
if (!story.getPermission("edit")) {
|
||||
throw Error("Permission denied for user " + name +
|
||||
" to edit story #" + id);
|
||||
}
|
||||
|
||||
story.mode = Story.FEATURED;
|
||||
return true;
|
||||
story.mode = Story.FEATURED;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -155,21 +155,21 @@ Api.mt.publishPost = function(id, name, password) {
|
|||
* @returns {Boolean}
|
||||
*/
|
||||
Api.mt.setPostCategories = function(id, name, password, categories) {
|
||||
if (!categories || !categories.length) {
|
||||
return;
|
||||
}
|
||||
if (!categories || !categories.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
var story = Api.getStory(id);
|
||||
var user = Api.getUser(name, password);
|
||||
var story = Api.getStory(id);
|
||||
var user = Api.getUser(name, password);
|
||||
|
||||
Api.constrain(story.site, user);
|
||||
if (!story.getPermission("edit")) {
|
||||
throw Error("Permission denied for user " + name +
|
||||
" to edit story #" + id);
|
||||
}
|
||||
Api.constrain(story.site, user);
|
||||
if (!story.getPermission("edit")) {
|
||||
throw Error("Permission denied for user " + name +
|
||||
" to edit story #" + id);
|
||||
}
|
||||
|
||||
story.setTags(categories);
|
||||
return true;
|
||||
story.setTags(categories);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -177,7 +177,7 @@ Api.mt.setPostCategories = function(id, name, password, categories) {
|
|||
* @returns {Array}
|
||||
*/
|
||||
Api.mt.supportedTextFilters = function() {
|
||||
return [];
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -185,7 +185,7 @@ Api.mt.supportedTextFilters = function() {
|
|||
* @returns {Array}
|
||||
*/
|
||||
Api.mt.getTrackbackPings = function() {
|
||||
return [];
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -193,9 +193,9 @@ Api.mt.getTrackbackPings = function() {
|
|||
* @returns {String[]}
|
||||
*/
|
||||
Api.mt.supportedMethods = function() {
|
||||
var result = [];
|
||||
for (var method in Api.mt) {
|
||||
result.push(method);
|
||||
}
|
||||
return result.sort();
|
||||
var result = [];
|
||||
for (var method in Api.mt) {
|
||||
result.push(method);
|
||||
}
|
||||
return result.sort();
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
|
@ -43,10 +43,10 @@ Archive.COLLECTION = "collection";
|
|||
* @extends HopObject
|
||||
*/
|
||||
Archive.prototype.constructor = function(name, type, parent) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.parent = parent;
|
||||
return this;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.parent = parent;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,12 +55,12 @@ Archive.prototype.constructor = function(name, type, parent) {
|
|||
* @returns {HopObject}
|
||||
*/
|
||||
Archive.prototype.getChildElement = function(name) {
|
||||
if (name.startsWith(Archive.PAGER)) {
|
||||
return new Archive(name, Archive.PAGER, this);
|
||||
} else if (!isNaN(name)) {
|
||||
return new Archive(name, Archive.COLLECTION, this);
|
||||
}
|
||||
return this.get(name);
|
||||
if (name.startsWith(Archive.PAGER)) {
|
||||
return new Archive(name, Archive.PAGER, this);
|
||||
} else if (!isNaN(name)) {
|
||||
return new Archive(name, Archive.COLLECTION, this);
|
||||
}
|
||||
return this.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,50 +69,50 @@ Archive.prototype.getChildElement = function(name) {
|
|||
* @returns {Boolean}
|
||||
*/
|
||||
Archive.prototype.getPermission = function(action) {
|
||||
var site = res.handlers.site;
|
||||
if (!site.getPermission("main") || site.archiveMode !== Site.PUBLIC) {
|
||||
return false;
|
||||
}
|
||||
switch (action) {
|
||||
case "main":
|
||||
case "page1":
|
||||
return true;
|
||||
case "previous":
|
||||
return this.getPage() > 1
|
||||
case "next":
|
||||
return this.getPage() < this.getSize() / this.getPageSize();
|
||||
}
|
||||
return false;
|
||||
var site = res.handlers.site;
|
||||
if (!site.getPermission("main") || site.archiveMode !== Site.PUBLIC) {
|
||||
return false;
|
||||
}
|
||||
switch (action) {
|
||||
case "main":
|
||||
case "page1":
|
||||
return true;
|
||||
case "previous":
|
||||
return this.getPage() > 1
|
||||
case "next":
|
||||
return this.getPage() < this.getSize() / this.getPageSize();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Archive.prototype.main_action = function() {
|
||||
var date = this.getDate();
|
||||
var dateString = String.EMPTY;
|
||||
switch (path.length - (this.type === Archive.PAGER ? 4 : 3)) {
|
||||
case 1:
|
||||
dateString = formatDate(date, "yyyy");
|
||||
break;
|
||||
case 2:
|
||||
dateString = formatDate(date, "MMM yyyy");
|
||||
break;
|
||||
case 3:
|
||||
var type = java.text.DateFormat.LONG;
|
||||
var locale = res.handlers.site.getLocale();
|
||||
var pattern = java.text.DateFormat.getDateInstance(type, locale).toPattern()
|
||||
dateString = formatDate(date, pattern);
|
||||
break;
|
||||
}
|
||||
var page = gettext("Page {0} of {1}", this.getPage(),
|
||||
Math.ceil(this.getSize() / this.getPageSize()));
|
||||
res.data.title = gettext("Story Archive {0} ({1})", dateString, page);
|
||||
res.data.body = this.renderSkinAsString("Archive#main");
|
||||
res.handlers.site.renderSkin("Site#page");
|
||||
res.handlers.site.log();
|
||||
return;
|
||||
var date = this.getDate();
|
||||
var dateString = String.EMPTY;
|
||||
switch (path.length - (this.type === Archive.PAGER ? 4 : 3)) {
|
||||
case 1:
|
||||
dateString = formatDate(date, "yyyy");
|
||||
break;
|
||||
case 2:
|
||||
dateString = formatDate(date, "MMM yyyy");
|
||||
break;
|
||||
case 3:
|
||||
var type = java.text.DateFormat.LONG;
|
||||
var locale = res.handlers.site.getLocale();
|
||||
var pattern = java.text.DateFormat.getDateInstance(type, locale).toPattern()
|
||||
dateString = formatDate(date, pattern);
|
||||
break;
|
||||
}
|
||||
var page = gettext("Page {0} of {1}", this.getPage(),
|
||||
Math.ceil(this.getSize() / this.getPageSize()));
|
||||
res.data.title = gettext("Story Archive {0} ({1})", dateString, page);
|
||||
res.data.body = this.renderSkinAsString("Archive#main");
|
||||
res.handlers.site.renderSkin("Site#page");
|
||||
res.handlers.site.log();
|
||||
return;
|
||||
}
|
||||
|
||||
Archive.prototype.page1_action = function() {
|
||||
return res.redirect(this.href());
|
||||
return res.redirect(this.href());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -121,21 +121,21 @@ Archive.prototype.page1_action = function() {
|
|||
* @returns {String}
|
||||
*/
|
||||
Archive.prototype.href = function(action) {
|
||||
var buffer = [];
|
||||
var archive = this;
|
||||
while (archive.parent) {
|
||||
buffer.push(archive.name);
|
||||
archive = archive.parent;
|
||||
}
|
||||
buffer.push(res.handlers.site.href("archive"));
|
||||
buffer.reverse();
|
||||
if (action) {
|
||||
if (this.type === Archive.PAGER) {
|
||||
buffer.pop();
|
||||
}
|
||||
buffer.push(action);
|
||||
}
|
||||
return buffer.join("/");
|
||||
var buffer = [];
|
||||
var archive = this;
|
||||
while (archive.parent) {
|
||||
buffer.push(archive.name);
|
||||
archive = archive.parent;
|
||||
}
|
||||
buffer.push(res.handlers.site.href("archive"));
|
||||
buffer.reverse();
|
||||
if (action) {
|
||||
if (this.type === Archive.PAGER) {
|
||||
buffer.pop();
|
||||
}
|
||||
buffer.push(action);
|
||||
}
|
||||
return buffer.join("/");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -146,76 +146,76 @@ Archive.prototype.href = function(action) {
|
|||
* @see renderLink
|
||||
*/
|
||||
Archive.prototype.link_macro = function(param, action, text) {
|
||||
if (!this.getPermission(action)) {
|
||||
return;
|
||||
}
|
||||
switch (action) {
|
||||
case "previous":
|
||||
var page = this.getPage() - 1; break;
|
||||
case "next":
|
||||
var page = this.getPage() + 1; break;
|
||||
}
|
||||
var action = "page" + page;
|
||||
return renderLink.call(global, param, action, text, this);
|
||||
if (!this.getPermission(action)) {
|
||||
return;
|
||||
}
|
||||
switch (action) {
|
||||
case "previous":
|
||||
var page = this.getPage() - 1; break;
|
||||
case "next":
|
||||
var page = this.getPage() + 1; break;
|
||||
}
|
||||
var action = "page" + page;
|
||||
return renderLink.call(global, param, action, text, this);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
Archive.prototype.stories_macro = function() {
|
||||
var day, storyDay;
|
||||
var page = this.getPage();
|
||||
var pageSize = this.getPageSize();
|
||||
var day, storyDay;
|
||||
var page = this.getPage();
|
||||
var pageSize = this.getPageSize();
|
||||
|
||||
var renderStory = function(story) {
|
||||
storyDay = formatDate(story.created, 'yyyy-MM-dd');
|
||||
if (day !== storyDay) {
|
||||
story.renderSkin("Story#date");
|
||||
day = storyDay;
|
||||
}
|
||||
story.renderSkin("Story#preview");
|
||||
return;
|
||||
}
|
||||
var renderStory = function(story) {
|
||||
storyDay = formatDate(story.created, 'yyyy-MM-dd');
|
||||
if (day !== storyDay) {
|
||||
story.renderSkin("Story#date");
|
||||
day = storyDay;
|
||||
}
|
||||
story.renderSkin("Story#preview");
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME: This is a little bit inconsistent and thus needs special care
|
||||
var archive = this.type === Archive.PAGER ? this.parent : this;
|
||||
if (!archive.parent) {
|
||||
var site = res.handlers.site;
|
||||
var offset = (page - 1) * pageSize;
|
||||
var stories = site.stories.featured.list(offset, pageSize);
|
||||
for each (var story in stories) {
|
||||
renderStory(story);
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
var sql = new Sql;
|
||||
sql.retrieve(Sql.ARCHIVE, res.handlers.site._id, this.getFilter(),
|
||||
Sql.ARCHIVEORDER, pageSize, (page - 1) * pageSize);
|
||||
sql.traverse(function() {
|
||||
var story = Story.getById(this.id);
|
||||
// FIXME: This is a little bit inconsistent and thus needs special care
|
||||
var archive = this.type === Archive.PAGER ? this.parent : this;
|
||||
if (!archive.parent) {
|
||||
var site = res.handlers.site;
|
||||
var offset = (page - 1) * pageSize;
|
||||
var stories = site.stories.featured.list(offset, pageSize);
|
||||
for each (var story in stories) {
|
||||
renderStory(story);
|
||||
});
|
||||
return;
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
var sql = new Sql;
|
||||
sql.retrieve(Sql.ARCHIVE, res.handlers.site._id, this.getFilter(),
|
||||
Sql.ARCHIVEORDER, pageSize, (page - 1) * pageSize);
|
||||
sql.traverse(function() {
|
||||
var story = Story.getById(this.id);
|
||||
renderStory(story);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Number}
|
||||
*/
|
||||
Archive.prototype.getSize = function() {
|
||||
// FIXME: This is a little bit inconsistent and thus needs special care
|
||||
var archive = this.type === Archive.PAGER ? this.parent : this;
|
||||
if (!archive.parent) {
|
||||
return res.handlers.site.stories.featured.size();
|
||||
}
|
||||
var size;
|
||||
var sql = new Sql;
|
||||
sql.retrieve(Sql.ARCHIVESIZE, res.handlers.site._id, this.getFilter());
|
||||
sql.traverse(function() {
|
||||
size = this.count;
|
||||
return;
|
||||
});
|
||||
return size;
|
||||
// FIXME: This is a little bit inconsistent and thus needs special care
|
||||
var archive = this.type === Archive.PAGER ? this.parent : this;
|
||||
if (!archive.parent) {
|
||||
return res.handlers.site.stories.featured.size();
|
||||
}
|
||||
var size;
|
||||
var sql = new Sql;
|
||||
sql.retrieve(Sql.ARCHIVESIZE, res.handlers.site._id, this.getFilter());
|
||||
sql.traverse(function() {
|
||||
size = this.count;
|
||||
return;
|
||||
});
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -223,66 +223,66 @@ Archive.prototype.getSize = function() {
|
|||
* @returns {String}
|
||||
*/
|
||||
Archive.prototype.getFilter = function() {
|
||||
var buffer = [];
|
||||
var archive = this;
|
||||
do {
|
||||
if (archive.type === Archive.COLLECTION) {
|
||||
buffer.unshift(Number(archive.name));
|
||||
}
|
||||
} while (archive = archive.parent);
|
||||
var buffer = [];
|
||||
var archive = this;
|
||||
do {
|
||||
if (archive.type === Archive.COLLECTION) {
|
||||
buffer.unshift(Number(archive.name));
|
||||
}
|
||||
} while (archive = archive.parent);
|
||||
|
||||
if (buffer.length < 0) {
|
||||
var now = new Date;
|
||||
buffer.push(now.getDate());
|
||||
buffer.push(now.getMonth() + 1);
|
||||
buffer.push(now.getFullYear());
|
||||
}
|
||||
if (buffer.length < 0) {
|
||||
var now = new Date;
|
||||
buffer.push(now.getDate());
|
||||
buffer.push(now.getMonth() + 1);
|
||||
buffer.push(now.getFullYear());
|
||||
}
|
||||
|
||||
res.push();
|
||||
var sql = new Sql;
|
||||
var keys = ["year", "month", "day"];
|
||||
for (var i in buffer) {
|
||||
sql.retrieve(Sql.ARCHIVEPART, keys[i], buffer[i]);
|
||||
res.write(sql);
|
||||
}
|
||||
return res.pop();
|
||||
res.push();
|
||||
var sql = new Sql;
|
||||
var keys = ["year", "month", "day"];
|
||||
for (var i in buffer) {
|
||||
sql.retrieve(Sql.ARCHIVEPART, keys[i], buffer[i]);
|
||||
res.write(sql);
|
||||
}
|
||||
return res.pop();
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Number}
|
||||
*/
|
||||
Archive.prototype.getPage = function() {
|
||||
if (this.type === Archive.PAGER) {
|
||||
return Number(this.name.substr(4));
|
||||
}
|
||||
return 1;
|
||||
if (this.type === Archive.PAGER) {
|
||||
return Number(this.name.substr(4));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Number}
|
||||
*/
|
||||
Archive.prototype.getPageSize = function() {
|
||||
return res.handlers.site.pageSize;
|
||||
return res.handlers.site.pageSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Date}
|
||||
*/
|
||||
Archive.prototype.getDate = function() {
|
||||
var date = new Date;
|
||||
var offset = path.contains(res.handlers.site.archive) + 1;
|
||||
if (offset > -1) {
|
||||
var archive;
|
||||
var buffer = [];
|
||||
for (var i=offset; i<path.length; i+=1) {
|
||||
archive = path[i];
|
||||
if (archive.type === Archive.COLLECTION) {
|
||||
buffer.push(Number(archive.name));
|
||||
}
|
||||
var date = new Date;
|
||||
var offset = path.contains(res.handlers.site.archive) + 1;
|
||||
if (offset > -1) {
|
||||
var archive;
|
||||
var buffer = [];
|
||||
for (var i=offset; i<path.length; i+=1) {
|
||||
archive = path[i];
|
||||
if (archive.type === Archive.COLLECTION) {
|
||||
buffer.push(Number(archive.name));
|
||||
}
|
||||
}
|
||||
buffer[0] && date.setYear(buffer[0]);
|
||||
buffer[1] && date.setMonth(buffer[1] - 1);
|
||||
buffer[2] && date.setDate(buffer[2]);
|
||||
return date;
|
||||
}
|
||||
}
|
||||
buffer[0] && date.setYear(buffer[0]);
|
||||
buffer[1] && date.setMonth(buffer[1] - 1);
|
||||
buffer[2] && date.setDate(buffer[2]);
|
||||
return date;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
|
@ -34,22 +34,22 @@ markgettext("choice");
|
|||
*
|
||||
*/
|
||||
Choice.add = function(title, poll) {
|
||||
HopObject.confirmConstructor(Choice);
|
||||
var choice = new Choice(title);
|
||||
choice.created = choice.modified = new Date;
|
||||
poll.add(choice);
|
||||
return choice;
|
||||
HopObject.confirmConstructor(Choice);
|
||||
var choice = new Choice(title);
|
||||
choice.created = choice.modified = new Date;
|
||||
poll.add(choice);
|
||||
return choice;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
Choice.remove = function() {
|
||||
if (this.constructor === Choice) {
|
||||
HopObject.remove.call(this);
|
||||
this.remove();
|
||||
}
|
||||
return;
|
||||
if (this.constructor === Choice) {
|
||||
HopObject.remove.call(this);
|
||||
this.remove();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,22 +64,22 @@ Choice.remove = function() {
|
|||
* @extends HopObject
|
||||
*/
|
||||
Choice.prototype.constructor = function(title) {
|
||||
HopObject.confirmConstructor.call(this);
|
||||
this.title = title;
|
||||
return this;
|
||||
HopObject.confirmConstructor.call(this);
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
Choice.prototype.selected_macro = function() {
|
||||
var votes;
|
||||
if (session.user && (votes = this._parent.votes.get(session.user.name))) {
|
||||
res.write(this === votes.choice);
|
||||
} else {
|
||||
res.write(false);
|
||||
}
|
||||
return;
|
||||
var votes;
|
||||
if (session.user && (votes = this._parent.votes.get(session.user.name))) {
|
||||
res.write(this === votes.choice);
|
||||
} else {
|
||||
res.write(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -88,28 +88,28 @@ Choice.prototype.selected_macro = function() {
|
|||
* @param {String} variant
|
||||
*/
|
||||
Choice.prototype.votes_macro = function(param, variant) {
|
||||
var votes = 0;
|
||||
if (variant) {
|
||||
if (variant.endsWith("%")) {
|
||||
variant = parseInt(variant) || 1;
|
||||
var max = this._parent.votes.size();
|
||||
votes = this.size() / max * variant;
|
||||
} else {
|
||||
var max = 1;
|
||||
this._parent.forEach(function() {
|
||||
var n = this.size();
|
||||
if (n > max) {
|
||||
max = n;
|
||||
}
|
||||
return;
|
||||
});
|
||||
votes = Math.round(this.size() / max * variant);
|
||||
}
|
||||
} else {
|
||||
votes = this.size();
|
||||
}
|
||||
if (!votes && param["default"]) {
|
||||
return param["default"];
|
||||
}
|
||||
return votes;
|
||||
var votes = 0;
|
||||
if (variant) {
|
||||
if (variant.endsWith("%")) {
|
||||
variant = parseInt(variant) || 1;
|
||||
var max = this._parent.votes.size();
|
||||
votes = this.size() / max * variant;
|
||||
} else {
|
||||
var max = 1;
|
||||
this._parent.forEach(function() {
|
||||
var n = this.size();
|
||||
if (n > max) {
|
||||
max = n;
|
||||
}
|
||||
return;
|
||||
});
|
||||
votes = Math.round(this.size() / max * variant);
|
||||
}
|
||||
} else {
|
||||
votes = this.size();
|
||||
}
|
||||
if (!votes && param["default"]) {
|
||||
return param["default"];
|
||||
}
|
||||
return votes;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
|
@ -33,8 +33,8 @@ markgettext("comment");
|
|||
/**
|
||||
* @see defineConstants
|
||||
*/
|
||||
Comment.getStatus = defineConstants(Comment, markgettext("deleted"),
|
||||
markgettext("pending"), markgettext("readonly"), markgettext("public"));
|
||||
Comment.getStatus = defineConstants(Comment, markgettext("deleted"),
|
||||
markgettext("pending"), markgettext("readonly"), markgettext("public"));
|
||||
|
||||
/**
|
||||
* Convenience method for easily adding a new comment to an existing story or comment.
|
||||
|
@ -43,56 +43,56 @@ Comment.getStatus = defineConstants(Comment, markgettext("deleted"),
|
|||
* @returns {Comment}
|
||||
*/
|
||||
Comment.add = function(data, parent) {
|
||||
HopObject.confirmConstructor(Comment);
|
||||
var story = parent.story || parent;
|
||||
var comment = new Comment;
|
||||
comment.name = String.EMPTY;
|
||||
comment.site = parent.site;
|
||||
comment.story = story;
|
||||
comment.parent = parent;
|
||||
comment.parent_type = parent._prototype; // FIXME: Set correct parent_type (Helma bug?)
|
||||
comment.status = Story.PUBLIC;
|
||||
comment.creator = comment.modifier = session.user;
|
||||
comment.created = comment.modified = new Date;
|
||||
comment.update(data);
|
||||
story.comments.add(comment); // Force addition to aggressively cached collection
|
||||
parent.add(comment);
|
||||
return comment;
|
||||
HopObject.confirmConstructor(Comment);
|
||||
var story = parent.story || parent;
|
||||
var comment = new Comment;
|
||||
comment.name = String.EMPTY;
|
||||
comment.site = parent.site;
|
||||
comment.story = story;
|
||||
comment.parent = parent;
|
||||
comment.parent_type = parent._prototype; // FIXME: Set correct parent_type (Helma bug?)
|
||||
comment.status = Story.PUBLIC;
|
||||
comment.creator = comment.modifier = session.user;
|
||||
comment.created = comment.modified = new Date;
|
||||
comment.update(data);
|
||||
story.comments.add(comment); // Force addition to aggressively cached collection
|
||||
parent.add(comment);
|
||||
return comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {String}
|
||||
*/
|
||||
Comment.remove = function(options) {
|
||||
if (this.constructor !== Comment) {
|
||||
return;
|
||||
}
|
||||
// Remove all comments of this comment’s creator if corresponding option is set
|
||||
if (options && options.mode === "user" && options.confirm === "1") {
|
||||
var membership = Membership.getByName(this.creator.name, this.site);
|
||||
// Not using HopObject.remove() because it will comepletely remove all comments
|
||||
membership.comments.forEach(function() {
|
||||
Comment.remove.call(this);
|
||||
})
|
||||
} else {
|
||||
// Mark comment as deleted if not already done so or if there are child comments
|
||||
if (this.size() > 0 && this.status !== Comment.DELETED) {
|
||||
this.status = Comment.DELETED;
|
||||
this.deleteMetadata();
|
||||
this.touch();
|
||||
return this.href();
|
||||
}
|
||||
// Completely remove comment and its children otherwise
|
||||
while (this.size() > 0) {
|
||||
Comment.remove.call(this.get(0));
|
||||
}
|
||||
// Explicitely remove comment from aggressively cached collections:
|
||||
(this.parent || this).removeChild(this);
|
||||
this.story.comments.removeChild(this);
|
||||
if (this.constructor !== Comment) {
|
||||
return;
|
||||
}
|
||||
// Remove all comments of this comment’s creator if corresponding option is set
|
||||
if (options && options.mode === "user" && options.confirm === "1") {
|
||||
var membership = Membership.getByName(this.creator.name, this.site);
|
||||
// Not using HopObject.remove() because it will comepletely remove all comments
|
||||
membership.comments.forEach(function() {
|
||||
Comment.remove.call(this);
|
||||
})
|
||||
} else {
|
||||
// Mark comment as deleted if not already done so or if there are child comments
|
||||
if (this.size() > 0 && this.status !== Comment.DELETED) {
|
||||
this.status = Comment.DELETED;
|
||||
this.deleteMetadata();
|
||||
this.remove();
|
||||
}
|
||||
return this.parent.href();
|
||||
this.touch();
|
||||
return this.href();
|
||||
}
|
||||
// Completely remove comment and its children otherwise
|
||||
while (this.size() > 0) {
|
||||
Comment.remove.call(this.get(0));
|
||||
}
|
||||
// Explicitely remove comment from aggressively cached collections:
|
||||
(this.parent || this).removeChild(this);
|
||||
this.story.comments.removeChild(this);
|
||||
this.deleteMetadata();
|
||||
this.remove();
|
||||
}
|
||||
return this.parent.href();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -105,176 +105,176 @@ Comment.remove = function(options) {
|
|||
* @extends Story
|
||||
*/
|
||||
Comment.prototype.constructor = function() {
|
||||
HopObject.confirmConstructor.call(this);
|
||||
return this;
|
||||
HopObject.confirmConstructor.call(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param {Object} action
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
Comment.prototype.getPermission = function(action) {
|
||||
switch (action) {
|
||||
case ".":
|
||||
case "main":
|
||||
if (this.status === Comment.DELETED) {
|
||||
return false;
|
||||
}
|
||||
// Break statement missing here by purpose!
|
||||
case "comment":
|
||||
return this.site.commentMode === Site.ENABLED &&
|
||||
this.story.getPermission(action) &&
|
||||
this.status !== Comment.PENDING;
|
||||
case "delete":
|
||||
return this.story.getPermission.call(this, "delete");
|
||||
case "edit":
|
||||
return this.status !== Comment.DELETED &&
|
||||
this.story.getPermission.call(this, "delete");
|
||||
}
|
||||
return false;
|
||||
switch (action) {
|
||||
case ".":
|
||||
case "main":
|
||||
if (this.status === Comment.DELETED) {
|
||||
return false;
|
||||
}
|
||||
// Break statement missing here by purpose!
|
||||
case "comment":
|
||||
return this.site.commentMode === Site.ENABLED &&
|
||||
this.story.getPermission(action) &&
|
||||
this.status !== Comment.PENDING;
|
||||
case "delete":
|
||||
return this.story.getPermission.call(this, "delete");
|
||||
case "edit":
|
||||
return this.status !== Comment.DELETED &&
|
||||
this.story.getPermission.call(this, "delete");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param {Object} action
|
||||
* @returns {String}
|
||||
*/
|
||||
Comment.prototype.href = function(action) {
|
||||
var buffer = [];
|
||||
switch (action) {
|
||||
case null:
|
||||
case undefined:
|
||||
case "":
|
||||
case ".":
|
||||
case "main":
|
||||
buffer.push(this.story.href(), "#", this._id);
|
||||
break;
|
||||
default:
|
||||
buffer.push(this.story.comments.href(), this._id, "/", action);
|
||||
}
|
||||
return buffer.join(String.EMPTY);
|
||||
var buffer = [];
|
||||
switch (action) {
|
||||
case null:
|
||||
case undefined:
|
||||
case "":
|
||||
case ".":
|
||||
case "main":
|
||||
buffer.push(this.story.href(), "#", this._id);
|
||||
break;
|
||||
default:
|
||||
buffer.push(this.story.comments.href(), this._id, "/", action);
|
||||
}
|
||||
return buffer.join(String.EMPTY);
|
||||
}
|
||||
|
||||
Comment.prototype.edit_action = function() {
|
||||
if (req.postParams.save) {
|
||||
try {
|
||||
this.update(req.postParams);
|
||||
delete session.data.backup;
|
||||
res.message = gettext("The comment was successfully updated.");;
|
||||
res.redirect(this.story.href() + "#" + this._id);
|
||||
} catch (ex) {
|
||||
res.message = ex;
|
||||
app.log(ex);
|
||||
}
|
||||
}
|
||||
|
||||
res.handlers.parent = this.parent;
|
||||
res.data.action = this.href(req.action);
|
||||
res.data.title = gettext("Edit Comment");
|
||||
res.data.body = this.renderSkinAsString("Comment#edit");
|
||||
this.site.renderSkin("Site#page");
|
||||
return;
|
||||
if (req.postParams.save) {
|
||||
try {
|
||||
this.update(req.postParams);
|
||||
delete session.data.backup;
|
||||
res.message = gettext("The comment was successfully updated.");;
|
||||
res.redirect(this.story.href() + "#" + this._id);
|
||||
} catch (ex) {
|
||||
res.message = ex;
|
||||
app.log(ex);
|
||||
}
|
||||
}
|
||||
|
||||
res.handlers.parent = this.parent;
|
||||
res.data.action = this.href(req.action);
|
||||
res.data.title = gettext("Edit Comment");
|
||||
res.data.body = this.renderSkinAsString("Comment#edit");
|
||||
this.site.renderSkin("Site#page");
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param {Object} data
|
||||
*/
|
||||
Comment.prototype.update = function(data) {
|
||||
if (!data.title && !data.text) {
|
||||
throw Error(gettext("Please enter at least something into the “title” or “text” field."));
|
||||
}
|
||||
// Get difference to current content before applying changes
|
||||
var delta = this.getDelta(data);
|
||||
this.title = data.title;
|
||||
this.text = data.text;
|
||||
this.setMetadata(data);
|
||||
if (!data.title && !data.text) {
|
||||
throw Error(gettext("Please enter at least something into the “title” or “text” field."));
|
||||
}
|
||||
// Get difference to current content before applying changes
|
||||
var delta = this.getDelta(data);
|
||||
this.title = data.title;
|
||||
this.text = data.text;
|
||||
this.setMetadata(data);
|
||||
|
||||
if (this.story.commentMode === Story.MODERATED) {
|
||||
this.status = Comment.PENDING;
|
||||
} else if (delta > 50) {
|
||||
this.modified = new Date;
|
||||
if (this.story.status !== Story.CLOSED) {
|
||||
this.site.modified = this.modified;
|
||||
}
|
||||
// We need persistence for adding the callback
|
||||
this.isTransient() && this.persist();
|
||||
res.handlers.site.callback(this);
|
||||
// Notification is sent in Story.comment_action()
|
||||
}
|
||||
this.clearCache();
|
||||
this.modifier = session.user;
|
||||
return;
|
||||
if (this.story.commentMode === Story.MODERATED) {
|
||||
this.status = Comment.PENDING;
|
||||
} else if (delta > 50) {
|
||||
this.modified = new Date;
|
||||
if (this.story.status !== Story.CLOSED) {
|
||||
this.site.modified = this.modified;
|
||||
}
|
||||
// We need persistence for adding the callback
|
||||
this.isTransient() && this.persist();
|
||||
res.handlers.site.callback(this);
|
||||
// Notification is sent in Story.comment_action()
|
||||
}
|
||||
this.clearCache();
|
||||
this.modifier = session.user;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {String}
|
||||
*/
|
||||
Comment.prototype.getConfirmText = function() {
|
||||
var size = this.size() + 1;
|
||||
if (this.status === Comment.DELETED && size > 1) {
|
||||
return gettext("You are about to delete a comment thread consisting of {0} postings.",
|
||||
size);
|
||||
}
|
||||
return gettext("You are about to delete a comment by user {0}.",
|
||||
this.creator.name);
|
||||
var size = this.size() + 1;
|
||||
if (this.status === Comment.DELETED && size > 1) {
|
||||
return gettext("You are about to delete a comment thread consisting of {0} postings.",
|
||||
size);
|
||||
}
|
||||
return gettext("You are about to delete a comment by user {0}.",
|
||||
this.creator.name);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param {String} name
|
||||
* @returns {HopObject}
|
||||
* @returns {HopObject}
|
||||
*/
|
||||
Comment.prototype.getMacroHandler = function(name) {
|
||||
if (name === "related") {
|
||||
var membership = Membership.getByName(this.creator.name, this.site);
|
||||
if (!membership || membership.comments.size() < 2 || this.status === Comment.DELETED) {
|
||||
return {}; // Work-around for issue 88
|
||||
}
|
||||
return membership.comments;
|
||||
}
|
||||
return null;
|
||||
if (name === "related") {
|
||||
var membership = Membership.getByName(this.creator.name, this.site);
|
||||
if (!membership || membership.comments.size() < 2 || this.status === Comment.DELETED) {
|
||||
return {}; // Work-around for issue 88
|
||||
}
|
||||
return membership.comments;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
Comment.prototype.text_macro = function() {
|
||||
if (this.status === Comment.DELETED) {
|
||||
res.write("<em>");
|
||||
res.write(this.modifier === this.creator ?
|
||||
gettext("This comment was removed by the author.") :
|
||||
gettext("This comment was removed."));
|
||||
res.writeln("</em>");
|
||||
} else {
|
||||
res.write(this.text);
|
||||
}
|
||||
return;
|
||||
if (this.status === Comment.DELETED) {
|
||||
res.write("<em>");
|
||||
res.write(this.modifier === this.creator ?
|
||||
gettext("This comment was removed by the author.") :
|
||||
gettext("This comment was removed."));
|
||||
res.writeln("</em>");
|
||||
} else {
|
||||
res.write(this.text);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
Comment.prototype.creator_macro = function() {
|
||||
return this.status === Comment.DELETED ? null :
|
||||
HopObject.prototype.creator_macro.apply(this, arguments);
|
||||
return this.status === Comment.DELETED ? null :
|
||||
HopObject.prototype.creator_macro.apply(this, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
Comment.prototype.modifier_macro = function() {
|
||||
return this.status === Comment.DELETED ? null :
|
||||
HopObject.prototype.modifier_macro.apply(this, arguments);
|
||||
return this.status === Comment.DELETED ? null :
|
||||
HopObject.prototype.modifier_macro.apply(this, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param {Object} param
|
||||
* @param {Object} action
|
||||
* @param {Object} text
|
||||
*/
|
||||
Comment.prototype.link_macro = function(param, action, text) {
|
||||
return HopObject.prototype.link_macro.call(this, param, action, text);
|
||||
return HopObject.prototype.link_macro.call(this, param, action, text);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
|
@ -43,40 +43,40 @@ this.handleMetadata("fileName");
|
|||
* @returns {File}
|
||||
*/
|
||||
File.add = function(data, site, user) {
|
||||
site || (site = res.handlers.site);
|
||||
user || (user = session.user);
|
||||
var file = new File;
|
||||
file.site = site;
|
||||
file.requests = 0;
|
||||
file.creator = file.modifier = user;
|
||||
file.created = file.modified = new Date;
|
||||
file.update(data);
|
||||
site.files.add(file);
|
||||
return file;
|
||||
site || (site = res.handlers.site);
|
||||
user || (user = session.user);
|
||||
var file = new File;
|
||||
file.site = site;
|
||||
file.requests = 0;
|
||||
file.creator = file.modifier = user;
|
||||
file.created = file.modified = new Date;
|
||||
file.update(data);
|
||||
site.files.add(file);
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
File.remove = function() {
|
||||
if (this.constructor === File) {
|
||||
this.getFile().remove();
|
||||
this.deleteMetadata();
|
||||
this.remove();
|
||||
}
|
||||
return;
|
||||
if (this.constructor === File) {
|
||||
this.getFile().remove();
|
||||
this.deleteMetadata();
|
||||
this.remove();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param {String} name
|
||||
*/
|
||||
File.getName = function(name) {
|
||||
if (name) {
|
||||
//return name.replace(/[^\w\d\s._-]/g, String.EMPTY);
|
||||
return String(name).trim().replace(/[\/\\:;?+\[\]{}|#"`<>^]/g, String.EMPTY);
|
||||
}
|
||||
return null;
|
||||
if (name) {
|
||||
//return name.replace(/[^\w\d\s._-]/g, String.EMPTY);
|
||||
return String(name).trim().replace(/[\/\\:;?+\[\]{}|#"`<>^]/g, String.EMPTY);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -84,12 +84,12 @@ File.getName = function(name) {
|
|||
* @param {String } url
|
||||
*/
|
||||
File.redirectOnUploadError = function(url) {
|
||||
if (req.data.helma_upload_error) {
|
||||
res.message = gettext("Sorry, the file exceeds the maximum upload limit of {0} kB.",
|
||||
formatNumber(app.appsProperties.uploadLimit));
|
||||
res.redirect(url);
|
||||
}
|
||||
return;
|
||||
if (req.data.helma_upload_error) {
|
||||
res.message = gettext("Sorry, the file exceeds the maximum upload limit of {0} kB.",
|
||||
formatNumber(app.appsProperties.uploadLimit));
|
||||
res.redirect(url);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -97,11 +97,11 @@ File.redirectOnUploadError = function(url) {
|
|||
* @param {String} url
|
||||
*/
|
||||
File.redirectOnExceededQuota = function(url) {
|
||||
if (res.handlers.site.getDiskSpace() < 0) {
|
||||
res.message = gettext("Sorry, there is no disk space left. Please try to delete some files or images first.");
|
||||
res.redirect(url);
|
||||
}
|
||||
return;
|
||||
if (res.handlers.site.getDiskSpace() < 0) {
|
||||
res.message = gettext("Sorry, there is no disk space left. Please try to delete some files or images first.");
|
||||
res.redirect(url);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -121,177 +121,177 @@ File.redirectOnExceededQuota = function(url) {
|
|||
* @extends HopObject
|
||||
*/
|
||||
File.prototype.constructor = function() {
|
||||
return this;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param {String} action
|
||||
* @return {Boolean}
|
||||
*/
|
||||
File.prototype.getPermission = function(action) {
|
||||
switch (action) {
|
||||
case ".":
|
||||
case "main":
|
||||
return true;
|
||||
case "delete":
|
||||
case "edit":
|
||||
return this._parent.getPermission("main") &&
|
||||
this.creator === session.user ||
|
||||
Membership.require(Membership.MANAGER) ||
|
||||
User.require(User.PRIVILEGED);
|
||||
}
|
||||
return false;
|
||||
switch (action) {
|
||||
case ".":
|
||||
case "main":
|
||||
return true;
|
||||
case "delete":
|
||||
case "edit":
|
||||
return this._parent.getPermission("main") &&
|
||||
this.creator === session.user ||
|
||||
Membership.require(Membership.MANAGER) ||
|
||||
User.require(User.PRIVILEGED);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
File.prototype.main_action = function() {
|
||||
if (Membership.require(Membership.SUBSCRIBER) &&
|
||||
User.require(User.REGULAR)) {
|
||||
this.requests += 1;
|
||||
}
|
||||
return res.redirect(this.getUrl());
|
||||
if (Membership.require(Membership.SUBSCRIBER) &&
|
||||
User.require(User.REGULAR)) {
|
||||
this.requests += 1;
|
||||
}
|
||||
return res.redirect(this.getUrl());
|
||||
}
|
||||
|
||||
File.prototype.edit_action = function() {
|
||||
File.redirectOnUploadError(this.href(req.action));
|
||||
File.redirectOnUploadError(this.href(req.action));
|
||||
|
||||
if (req.postParams.save) {
|
||||
try {
|
||||
File.redirectOnExceededQuota(this.href(req.action));
|
||||
this.update(req.postParams);
|
||||
res.message = gettext("The changes were saved successfully.");
|
||||
res.redirect(this._parent.href());
|
||||
} catch (ex) {
|
||||
res.message = ex;
|
||||
app.log(ex);
|
||||
}
|
||||
}
|
||||
|
||||
res.data.action = this.href(req.action);
|
||||
res.data.title = gettext("Edit File");
|
||||
res.data.body = this.renderSkinAsString("$File#edit");
|
||||
return this.site.renderSkin("Site#page");
|
||||
if (req.postParams.save) {
|
||||
try {
|
||||
File.redirectOnExceededQuota(this.href(req.action));
|
||||
this.update(req.postParams);
|
||||
res.message = gettext("The changes were saved successfully.");
|
||||
res.redirect(this._parent.href());
|
||||
} catch (ex) {
|
||||
res.message = ex;
|
||||
app.log(ex);
|
||||
}
|
||||
}
|
||||
|
||||
res.data.action = this.href(req.action);
|
||||
res.data.title = gettext("Edit File");
|
||||
res.data.body = this.renderSkinAsString("$File#edit");
|
||||
return this.site.renderSkin("Site#page");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param {String} name
|
||||
* @returns {Object}
|
||||
*/
|
||||
File.prototype.getFormValue = function(name) {
|
||||
var self = this;
|
||||
|
||||
var getOrigin = function(str) {
|
||||
var origin = req.postParams.file_origin || self.origin;
|
||||
if (origin && origin.contains("://")) {
|
||||
return origin;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (req.isPost()) {
|
||||
if (name === "file") {
|
||||
return getOrigin();
|
||||
}
|
||||
return req.postParams[name];
|
||||
}
|
||||
switch (name) {
|
||||
case "file":
|
||||
var self = this;
|
||||
|
||||
var getOrigin = function(str) {
|
||||
var origin = req.postParams.file_origin || self.origin;
|
||||
if (origin && origin.contains("://")) {
|
||||
return origin;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (req.isPost()) {
|
||||
if (name === "file") {
|
||||
return getOrigin();
|
||||
}
|
||||
return this[name];
|
||||
}
|
||||
return req.postParams[name];
|
||||
}
|
||||
switch (name) {
|
||||
case "file":
|
||||
return getOrigin();
|
||||
}
|
||||
return this[name];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param {Object} data
|
||||
*/
|
||||
File.prototype.update = function(data) {
|
||||
if (data.uploadError) {
|
||||
app.log(data.uploadError);
|
||||
// Looks like the file uploaded has exceeded the upload limit ...
|
||||
throw Error(gettext("File size is exceeding the upload limit."));
|
||||
}
|
||||
|
||||
if (!data.file_origin) {
|
||||
if (this.isTransient()) {
|
||||
throw Error(gettext("There was nothing to upload. Please be sure to choose a file."));
|
||||
}
|
||||
} else if (data.file_origin !== this.origin) {
|
||||
var mime = data.file;
|
||||
if (mime.contentLength < 1) {
|
||||
mime = getURL(data.file_origin);
|
||||
if (!mime) {
|
||||
throw Error(gettext("Could not fetch the file from the given URL."));
|
||||
}
|
||||
}
|
||||
if (data.uploadError) {
|
||||
app.log(data.uploadError);
|
||||
// Looks like the file uploaded has exceeded the upload limit ...
|
||||
throw Error(gettext("File size is exceeding the upload limit."));
|
||||
}
|
||||
|
||||
this.origin = data.file_origin;
|
||||
var mimeName = mime.normalizeFilename(mime.name);
|
||||
this.contentLength = mime.contentLength;
|
||||
this.contentType = mime.contentType;
|
||||
|
||||
if (!this.name) {
|
||||
var name = File.getName(data.name) || mimeName.split(".")[0];
|
||||
this.name = this.site.files.getAccessName(name);
|
||||
if (!data.file_origin) {
|
||||
if (this.isTransient()) {
|
||||
throw Error(gettext("There was nothing to upload. Please be sure to choose a file."));
|
||||
}
|
||||
} else if (data.file_origin !== this.origin) {
|
||||
var mime = data.file;
|
||||
if (mime.contentLength < 1) {
|
||||
mime = getURL(data.file_origin);
|
||||
if (!mime) {
|
||||
throw Error(gettext("Could not fetch the file from the given URL."));
|
||||
}
|
||||
}
|
||||
|
||||
// Make the file persistent before proceeding with writing
|
||||
// it to disk (also see Helma bug #607)
|
||||
this.isTransient() && this.persist();
|
||||
this.origin = data.file_origin;
|
||||
var mimeName = mime.normalizeFilename(mime.name);
|
||||
this.contentLength = mime.contentLength;
|
||||
this.contentType = mime.contentType;
|
||||
|
||||
var extension = mimeName.substr(mimeName.lastIndexOf(".")) || String.EMPTY;
|
||||
var fileName = this.name + extension;
|
||||
if (fileName !== this.fileName) {
|
||||
// Remove existing file if the file name has changed
|
||||
this.getFile().remove();
|
||||
}
|
||||
this.fileName = fileName;
|
||||
var file = this.getFile();
|
||||
mime.writeToFile(file.getParent(), file.getName());
|
||||
}
|
||||
|
||||
// FIXME: one day?
|
||||
//this.setTags(data.tags || data.tag_array);
|
||||
this.description = data.description;
|
||||
this.touch();
|
||||
return;
|
||||
if (!this.name) {
|
||||
var name = File.getName(data.name) || mimeName.split(".")[0];
|
||||
this.name = this.site.files.getAccessName(name);
|
||||
}
|
||||
|
||||
// Make the file persistent before proceeding with writing
|
||||
// it to disk (also see Helma bug #607)
|
||||
this.isTransient() && this.persist();
|
||||
|
||||
var extension = mimeName.substr(mimeName.lastIndexOf(".")) || String.EMPTY;
|
||||
var fileName = this.name + extension;
|
||||
if (fileName !== this.fileName) {
|
||||
// Remove existing file if the file name has changed
|
||||
this.getFile().remove();
|
||||
}
|
||||
this.fileName = fileName;
|
||||
var file = this.getFile();
|
||||
mime.writeToFile(file.getParent(), file.getName());
|
||||
}
|
||||
|
||||
// FIXME: one day?
|
||||
//this.setTags(data.tags || data.tag_array);
|
||||
this.description = data.description;
|
||||
this.touch();
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
File.prototype.url_macro = function() {
|
||||
return res.write(this.url || this.getUrl());
|
||||
return res.write(this.url || this.getUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param {Object} param
|
||||
*/
|
||||
File.prototype.contentLength_macro = function(param) {
|
||||
return res.write((this.contentLength / 1024).format("###,###") + " KB");
|
||||
return res.write((this.contentLength / 1024).format("###,###") + " KB");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
File.prototype.getFile = function() {
|
||||
var site = this.site || res.handlers.site;
|
||||
return site.getStaticFile("files/" + this.fileName);
|
||||
var site = this.site || res.handlers.site;
|
||||
return site.getStaticFile("files/" + this.fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
File.prototype.getUrl = function() {
|
||||
var site = this.site || res.handlers.site;
|
||||
return site.getStaticUrl("files/" + this.fileName);
|
||||
var site = this.site || res.handlers.site;
|
||||
return site.getStaticUrl("files/" + this.fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {String}
|
||||
*/
|
||||
File.prototype.getConfirmText = function() {
|
||||
return gettext("You are about to delete the file {0}.", this.name);
|
||||
return gettext("You are about to delete the file {0}.", this.name);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
|
@ -37,69 +37,69 @@ markgettext("files");
|
|||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param {String} action
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
Files.prototype.getPermission = function(action) {
|
||||
if (!this._parent.getPermission("main")) {
|
||||
return false;
|
||||
}
|
||||
switch (action) {
|
||||
case ".":
|
||||
case "main":
|
||||
case "create":
|
||||
return Site.require(Site.OPEN) && session.user ||
|
||||
Membership.require(Membership.CONTRIBUTOR) ||
|
||||
User.require(User.PRIVILEGED);
|
||||
case "all":
|
||||
return Membership.require(Membership.MANAGER) ||
|
||||
User.require(User.PRIVILEGED);
|
||||
}
|
||||
return false;
|
||||
if (!this._parent.getPermission("main")) {
|
||||
return false;
|
||||
}
|
||||
switch (action) {
|
||||
case ".":
|
||||
case "main":
|
||||
case "create":
|
||||
return Site.require(Site.OPEN) && session.user ||
|
||||
Membership.require(Membership.CONTRIBUTOR) ||
|
||||
User.require(User.PRIVILEGED);
|
||||
case "all":
|
||||
return Membership.require(Membership.MANAGER) ||
|
||||
User.require(User.PRIVILEGED);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Files.prototype.create_action = function() {
|
||||
File.redirectOnUploadError(this.href(req.action));
|
||||
File.redirectOnExceededQuota(this.href());
|
||||
File.redirectOnUploadError(this.href(req.action));
|
||||
File.redirectOnExceededQuota(this.href());
|
||||
|
||||
if (req.postParams.save) {
|
||||
try {
|
||||
var file = File.add(req.postParams);
|
||||
file.notify(req.action);
|
||||
res.message = gettext('The file was successfully added.');
|
||||
res.redirect(this.href());
|
||||
} catch (ex) {
|
||||
res.message = ex;
|
||||
app.log(ex);
|
||||
}
|
||||
}
|
||||
|
||||
res.data.action = this.href(req.action);
|
||||
res.data.title = gettext("Add File");
|
||||
HopObject.confirmConstructor(File);
|
||||
res.data.body = (new File).renderSkinAsString("$File#edit");
|
||||
this._parent.renderSkin("Site#page");
|
||||
return;
|
||||
if (req.postParams.save) {
|
||||
try {
|
||||
var file = File.add(req.postParams);
|
||||
file.notify(req.action);
|
||||
res.message = gettext('The file was successfully added.');
|
||||
res.redirect(this.href());
|
||||
} catch (ex) {
|
||||
res.message = ex;
|
||||
app.log(ex);
|
||||
}
|
||||
}
|
||||
|
||||
res.data.action = this.href(req.action);
|
||||
res.data.title = gettext("Add File");
|
||||
HopObject.confirmConstructor(File);
|
||||
res.data.body = (new File).renderSkinAsString("$File#edit");
|
||||
this._parent.renderSkin("Site#page");
|
||||
return;
|
||||
}
|
||||
|
||||
Files.prototype.main_action = function() {
|
||||
var files = User.getMembership().files;
|
||||
res.data.list = renderList(files, "$File#listItem", 10, req.queryParams.page);
|
||||
res.data.pager = renderPager(files, this.href(),
|
||||
10, req.queryParams.page);
|
||||
res.data.title = gettext("Member Files");
|
||||
res.data.body = this.renderSkinAsString("$Files#main");
|
||||
this._parent.renderSkin("Site#page");
|
||||
return;
|
||||
var files = User.getMembership().files;
|
||||
res.data.list = renderList(files, "$File#listItem", 10, req.queryParams.page);
|
||||
res.data.pager = renderPager(files, this.href(),
|
||||
10, req.queryParams.page);
|
||||
res.data.title = gettext("Member Files");
|
||||
res.data.body = this.renderSkinAsString("$Files#main");
|
||||
this._parent.renderSkin("Site#page");
|
||||
return;
|
||||
}
|
||||
|
||||
Files.prototype.all_action = function() {
|
||||
res.data.list = renderList(this, "$File#listItem", 10, req.queryParams.page);
|
||||
res.data.pager = renderPager(this,
|
||||
this.href(req.action), 10, req.queryParams.page);
|
||||
res.data.title = gettext("All Files");
|
||||
res.data.body = this.renderSkinAsString("$Files#main");
|
||||
this._parent.renderSkin("Site#page");
|
||||
return;
|
||||
res.data.list = renderList(this, "$File#listItem", 10, req.queryParams.page);
|
||||
res.data.pager = renderPager(this,
|
||||
this.href(req.action), 10, req.queryParams.page);
|
||||
res.data.title = gettext("All Files");
|
||||
res.data.body = this.renderSkinAsString("$Files#main");
|
||||
this._parent.renderSkin("Site#page");
|
||||
return;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -10,7 +10,7 @@
|
|||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
|
@ -40,77 +40,77 @@ var Exporter = {}
|
|||
* @param {User} user The user whose content will be exported.
|
||||
*/
|
||||
Exporter.run = function(site, user) {
|
||||
try {
|
||||
var file;
|
||||
if (site.export_id && (file = File.getById(site.export_id))) {
|
||||
File.remove.call(file);
|
||||
}
|
||||
try {
|
||||
var file;
|
||||
if (site.export_id && (file = File.getById(site.export_id))) {
|
||||
File.remove.call(file);
|
||||
}
|
||||
|
||||
var rssUrl = site.href("rss.xml");
|
||||
var baseDir = site.getStaticFile();
|
||||
var member = site.members.get(user.name);
|
||||
var rssUrl = site.href("rss.xml");
|
||||
var baseDir = site.getStaticFile();
|
||||
var member = site.members.get(user.name);
|
||||
|
||||
var xml = new helma.File(baseDir, "export.xml");
|
||||
xml.remove();
|
||||
xml.open();
|
||||
var xml = new helma.File(baseDir, "export.xml");
|
||||
xml.remove();
|
||||
xml.open();
|
||||
|
||||
var add = function(s) {
|
||||
return xml.write(s);
|
||||
}
|
||||
var add = function(s) {
|
||||
return xml.write(s);
|
||||
}
|
||||
|
||||
add('<?xml version="1.0" encoding="UTF-8"?>');
|
||||
add('<?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?>');
|
||||
add('<feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:thr="http://purl.org/syndication/thread/1.0">');
|
||||
add('<id>tag:blogger.com,1999:blog-' + site._id + '.archive</id>');
|
||||
add('<updated>' + site.modified.format(Date.ISOFORMAT) + '</updated>');
|
||||
add('<title type="text">' + encodeXml(site.title) + '</title>');
|
||||
add('<link rel="http://schemas.google.com/g/2005#feed" type="application/rss+xml" href="' + rssUrl + '"/>');
|
||||
add('<link rel="self" type="application/rss+xml" href="' + rssUrl + '"/>');
|
||||
add('<link rel="http://schemas.google.com/g/2005#post" type="application/rss+xml" href="' + rssUrl + '"/>');
|
||||
add('<link rel="alternate" type="text/html" href="' + site.href() + '"/>');
|
||||
add('<?xml version="1.0" encoding="UTF-8"?>');
|
||||
add('<?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?>');
|
||||
add('<feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:thr="http://purl.org/syndication/thread/1.0">');
|
||||
add('<id>tag:blogger.com,1999:blog-' + site._id + '.archive</id>');
|
||||
add('<updated>' + site.modified.format(Date.ISOFORMAT) + '</updated>');
|
||||
add('<title type="text">' + encodeXml(site.title) + '</title>');
|
||||
add('<link rel="http://schemas.google.com/g/2005#feed" type="application/rss+xml" href="' + rssUrl + '"/>');
|
||||
add('<link rel="self" type="application/rss+xml" href="' + rssUrl + '"/>');
|
||||
add('<link rel="http://schemas.google.com/g/2005#post" type="application/rss+xml" href="' + rssUrl + '"/>');
|
||||
add('<link rel="alternate" type="text/html" href="' + site.href() + '"/>');
|
||||
add('<author>');
|
||||
add('<name>' + site.creator.name + '</name>');
|
||||
add('<email>' + site.creator.email + '</email>');
|
||||
add('</author>');
|
||||
// Currently, blogger.com does not accept other generators
|
||||
//add('<generator version="' + Root.VERSION + '" uri="' + root.href() + '">Antville</generator>');
|
||||
add('<generator version="7.00" uri="http://www.blogger.com">Blogger</generator>');
|
||||
member.stories.forEach(function() {
|
||||
add('<entry>');
|
||||
add('<id>tag:blogger.com,1999:blog-' + site._id + '.post-' + this._id + '</id>');
|
||||
add('<published>' + this.created.format(Date.ISOFORMAT) + '</published>');
|
||||
add('<updated>' + this.modified.format(Date.ISOFORMAT) + '</updated>');
|
||||
add('<title type="text">' + (this.title ? encodeXml(this.title.stripTags()) : '') + '</title>');
|
||||
add('<content type="html">' + encodeXml(this.format_filter(this.text, {})) + '</content>');
|
||||
add('<link rel="alternate" type="text/html" href="' + this.href() + '"></link>');
|
||||
add('<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/blogger/2008/kind#post"/>');
|
||||
add('<author>');
|
||||
add('<name>' + site.creator.name + '</name>');
|
||||
add('<email>' + site.creator.email + '</email>');
|
||||
add('<name>' + this.creator.name + '</name>');
|
||||
this.creator.url && add('<uri>' + this.creator.url + '</uri>');
|
||||
add('<email>' + this.creator.email + '</email>');
|
||||
add('</author>');
|
||||
// Currently, blogger.com does not accept other generators
|
||||
//add('<generator version="' + Root.VERSION + '" uri="' + root.href() + '">Antville</generator>');
|
||||
add('<generator version="7.00" uri="http://www.blogger.com">Blogger</generator>');
|
||||
member.stories.forEach(function() {
|
||||
add('<entry>');
|
||||
add('<id>tag:blogger.com,1999:blog-' + site._id + '.post-' + this._id + '</id>');
|
||||
add('<published>' + this.created.format(Date.ISOFORMAT) + '</published>');
|
||||
add('<updated>' + this.modified.format(Date.ISOFORMAT) + '</updated>');
|
||||
add('<title type="text">' + (this.title ? encodeXml(this.title.stripTags()) : '') + '</title>');
|
||||
add('<content type="html">' + encodeXml(this.format_filter(this.text, {})) + '</content>');
|
||||
add('<link rel="alternate" type="text/html" href="' + this.href() + '"></link>');
|
||||
add('<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/blogger/2008/kind#post"/>');
|
||||
add('<author>');
|
||||
add('<name>' + this.creator.name + '</name>');
|
||||
this.creator.url && add('<uri>' + this.creator.url + '</uri>');
|
||||
add('<email>' + this.creator.email + '</email>');
|
||||
add('</author>');
|
||||
add('</entry>');
|
||||
});
|
||||
add('</feed>');
|
||||
add('</entry>');
|
||||
});
|
||||
add('</feed>');
|
||||
|
||||
xml.close();
|
||||
// Provide the exported data as downloadable file
|
||||
// FIXME: Adding a file to a site could be a little bit simpler :/
|
||||
file = new File;
|
||||
file.site = site;
|
||||
file.update({file: {contentLength: 0}, file_origin: "file://" +
|
||||
xml.getPath(), name: site.name + "-export"});
|
||||
site.files.add(file);
|
||||
file.creator = user;
|
||||
site.export_id = file._id;
|
||||
} catch (ex) {
|
||||
app.log(ex);
|
||||
} finally {
|
||||
xml.close();
|
||||
xml.remove();
|
||||
}
|
||||
xml.close();
|
||||
// Provide the exported data as downloadable file
|
||||
// FIXME: Adding a file to a site could be a little bit simpler :/
|
||||
file = new File;
|
||||
file.site = site;
|
||||
file.update({file: {contentLength: 0}, file_origin: "file://" +
|
||||
xml.getPath(), name: site.name + "-export"});
|
||||
site.files.add(file);
|
||||
file.creator = user;
|
||||
site.export_id = file._id;
|
||||
} catch (ex) {
|
||||
app.log(ex);
|
||||
} finally {
|
||||
xml.close();
|
||||
xml.remove();
|
||||
}
|
||||
|
||||
// Reset the site’s export status
|
||||
site.job = null;
|
||||
return;
|
||||
// Reset the site’s export status
|
||||
site.job = null;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
|
@ -34,11 +34,11 @@
|
|||
* @param {String} id The identifier of the desired feature.
|
||||
*/
|
||||
global.feature_macro = function(param, id) {
|
||||
var func, feature = Feature.get(id);
|
||||
if (feature && (func = feature.main)) {
|
||||
func.constructor === Function && func(param);
|
||||
}
|
||||
return;
|
||||
var func, feature = Feature.get(id);
|
||||
if (feature && (func = feature.main)) {
|
||||
func.constructor === Function && func(param);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,19 +49,19 @@ global.feature_macro = function(param, id) {
|
|||
* @param {Object} feature The initial properties of the feature.
|
||||
*/
|
||||
var Feature = function(id, url, feature) {
|
||||
var self = this;
|
||||
var self = this;
|
||||
|
||||
this.__defineGetter__("id", function() {return id});
|
||||
this.__defineGetter__("id", function() {return id});
|
||||
|
||||
for (let i in feature) {
|
||||
this[i] = feature[i];
|
||||
}
|
||||
for (let i in feature) {
|
||||
this[i] = feature[i];
|
||||
}
|
||||
|
||||
this.toString = function() {
|
||||
return "[Feature: " + html.linkAsString({href: url}, id) + "]";
|
||||
}
|
||||
this.toString = function() {
|
||||
return "[Feature: " + html.linkAsString({href: url}, id) + "]";
|
||||
}
|
||||
|
||||
return this;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,18 +70,18 @@ var Feature = function(id, url, feature) {
|
|||
* @returns {Feature}
|
||||
*/
|
||||
Feature.add = function(id, url, feature) {
|
||||
if (!id || !url) {
|
||||
throw Error("Insufficient arguments");
|
||||
}
|
||||
if (!id || !url) {
|
||||
throw Error("Insufficient arguments");
|
||||
}
|
||||
|
||||
var existingFeature = Feature.get(id);
|
||||
if (existingFeature) {
|
||||
app.log("Warning! Overwriting already present feature with ID " + id);
|
||||
Feature.remove(existingFeature);
|
||||
}
|
||||
var existingFeature = Feature.get(id);
|
||||
if (existingFeature) {
|
||||
app.log("Warning! Overwriting already present feature with ID " + id);
|
||||
Feature.remove(existingFeature);
|
||||
}
|
||||
|
||||
Feature.list().push(new Feature(id, url, feature));
|
||||
return this;
|
||||
Feature.list().push(new Feature(id, url, feature));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,14 +90,14 @@ Feature.add = function(id, url, feature) {
|
|||
* @returns {Number} The resulting number of features still in the registry.
|
||||
*/
|
||||
Feature.remove = function(feature) {
|
||||
var features = Feature.list();
|
||||
if (feature === "*") {
|
||||
features.length = 0;
|
||||
} else if (feature) {
|
||||
var index = features.indexOf(feature);
|
||||
(index > -1) && features.splice(index, 1);
|
||||
}
|
||||
return features.length;
|
||||
var features = Feature.list();
|
||||
if (feature === "*") {
|
||||
features.length = 0;
|
||||
} else if (feature) {
|
||||
var index = features.indexOf(feature);
|
||||
(index > -1) && features.splice(index, 1);
|
||||
}
|
||||
return features.length;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -105,7 +105,7 @@ Feature.remove = function(feature) {
|
|||
* @returns {Feature[]}
|
||||
*/
|
||||
Feature.list = function() {
|
||||
return app.data.features;
|
||||
return app.data.features;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -114,12 +114,12 @@ Feature.list = function() {
|
|||
* @returns {Feature}
|
||||
*/
|
||||
Feature.get = function(id) {
|
||||
for each (let feature in Feature.list()) {
|
||||
if (feature.id === id) {
|
||||
return feature;
|
||||
}
|
||||
}
|
||||
return;
|
||||
for each (let feature in Feature.list()) {
|
||||
if (feature.id === id) {
|
||||
return feature;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -129,32 +129,32 @@ Feature.get = function(id) {
|
|||
* @returns {Object}
|
||||
*/
|
||||
Feature.invoke = function(id, callback) {
|
||||
id || (id = "*");
|
||||
if (callback) {
|
||||
var feature, method, result;
|
||||
var args = Array.prototype.slice.call(arguments, 2);
|
||||
if (id === "*") {
|
||||
for each (feature in Feature.list()) {
|
||||
method = feature[String(callback)];
|
||||
if (method && method.constructor === Function) {
|
||||
result = method.apply(feature, args);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
feature = Feature.get(id);
|
||||
if (feature) {
|
||||
if (callback.constructor === Function) {
|
||||
result = callback.apply(feature, args);
|
||||
} else {
|
||||
method = feature[callback];
|
||||
if (method && method.constructor === Function) {
|
||||
result = method.apply(feature, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
id || (id = "*");
|
||||
if (callback) {
|
||||
var feature, method, result;
|
||||
var args = Array.prototype.slice.call(arguments, 2);
|
||||
if (id === "*") {
|
||||
for each (feature in Feature.list()) {
|
||||
method = feature[String(callback)];
|
||||
if (method && method.constructor === Function) {
|
||||
result = method.apply(feature, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
feature = Feature.get(id);
|
||||
if (feature) {
|
||||
if (callback.constructor === Function) {
|
||||
result = callback.apply(feature, args);
|
||||
} else {
|
||||
method = feature[callback];
|
||||
if (method && method.constructor === Function) {
|
||||
result = method.apply(feature, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -163,11 +163,11 @@ Feature.invoke = function(id, callback) {
|
|||
* @returns {Boolean}
|
||||
*/
|
||||
Feature.getPermission = function(action) {
|
||||
for each (let feature in Feature.list()) {
|
||||
let method = feature._getPermission;
|
||||
if (method && method.constructor === Function && method.call(this, action)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
for each (let feature in Feature.list()) {
|
||||
let method = feature._getPermission;
|
||||
if (method && method.constructor === Function && method.call(this, action)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
|
@ -10,7 +10,7 @@
|
|||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
|
@ -28,53 +28,53 @@
|
|||
*/
|
||||
|
||||
var FlexiPath = function(name, parent) {
|
||||
var self = this;
|
||||
var self = this;
|
||||
|
||||
this._id = name;
|
||||
this._parent = parent;
|
||||
this._patterns = {};
|
||||
this._id = name;
|
||||
this._parent = parent;
|
||||
this._patterns = {};
|
||||
|
||||
this.__defineGetter__("patterns", function() {
|
||||
var ref = this;
|
||||
while (ref._parent.constructor === FlexiPath) {
|
||||
ref = ref._parent;
|
||||
}
|
||||
return ref._patterns;
|
||||
});
|
||||
this.__defineGetter__("patterns", function() {
|
||||
var ref = this;
|
||||
while (ref._parent.constructor === FlexiPath) {
|
||||
ref = ref._parent;
|
||||
}
|
||||
return ref._patterns;
|
||||
});
|
||||
|
||||
this.addUrlPattern = function(pattern, callback) {
|
||||
this._patterns[pattern] = callback;
|
||||
return;
|
||||
}
|
||||
this.addUrlPattern = function(pattern, callback) {
|
||||
this._patterns[pattern] = callback;
|
||||
return;
|
||||
}
|
||||
|
||||
this.href = function(action) {
|
||||
var href = [];
|
||||
var ref = this;
|
||||
while (ref._parent === this.constructor) {
|
||||
href.unshift(ref._id);
|
||||
ref = ref._parent;
|
||||
}
|
||||
//href.push("/");
|
||||
if (action) {
|
||||
href.push(action);
|
||||
}
|
||||
return root.api.href() + href.join("/");
|
||||
}
|
||||
this.href = function(action) {
|
||||
var href = [];
|
||||
var ref = this;
|
||||
while (ref._parent === this.constructor) {
|
||||
href.unshift(ref._id);
|
||||
ref = ref._parent;
|
||||
}
|
||||
//href.push("/");
|
||||
if (action) {
|
||||
href.push(action);
|
||||
}
|
||||
return root.api.href() + href.join("/");
|
||||
}
|
||||
|
||||
this.getChildElement = function(name) {
|
||||
return new this.constructor(name, self);
|
||||
}
|
||||
this.getChildElement = function(name) {
|
||||
return new this.constructor(name, self);
|
||||
}
|
||||
|
||||
return this;
|
||||
return this;
|
||||
};
|
||||
|
||||
FlexiPath.prototype.main_action = function() {
|
||||
for (let pattern in this.patterns) {
|
||||
let match;
|
||||
let re = new RegExp(pattern);
|
||||
if (match = req.path.match(re)) {
|
||||
return this.patterns[pattern].apply(this, match);
|
||||
}
|
||||
}
|
||||
return;
|
||||
for (let pattern in this.patterns) {
|
||||
let match;
|
||||
let re = new RegExp(pattern);
|
||||
if (match = req.path.match(re)) {
|
||||
return this.patterns[pattern].apply(this, match);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -10,7 +10,7 @@
|
|||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
|
@ -39,36 +39,36 @@ var Importer = {}
|
|||
* @param {User} user The user who will become the creator of the site’s imported content.
|
||||
*/
|
||||
Importer.run = function(site, user) {
|
||||
try {
|
||||
var xml = File.getById(site.import_id);
|
||||
if (xml) {
|
||||
var file = new java.io.File(xml.getFile());
|
||||
var reader = new rome.XmlReader(file);
|
||||
var input = new rome.SyndFeedInput(true);
|
||||
var feed = input.build(reader);
|
||||
Api.constrain(site, user);
|
||||
for (var i=0; i<feed.entries.size(); i+=1) {
|
||||
var entry = feed.entries.get(i);
|
||||
var category = entry.categories.get(0);
|
||||
if (category.name !== "http://schemas.google.com/blogger/2008/kind#post") {
|
||||
continue;
|
||||
}
|
||||
var story = Story.add({
|
||||
title: entry.title,
|
||||
text: entry.description || entry.contents.get(0).value,
|
||||
created: entry.publishedDate.format("yyyy-MM-dd HH:mm"),
|
||||
status: Story.CLOSED,
|
||||
mode: Story.FEATURED
|
||||
}, site, user);
|
||||
}
|
||||
File.remove.call(xml);
|
||||
try {
|
||||
var xml = File.getById(site.import_id);
|
||||
if (xml) {
|
||||
var file = new java.io.File(xml.getFile());
|
||||
var reader = new rome.XmlReader(file);
|
||||
var input = new rome.SyndFeedInput(true);
|
||||
var feed = input.build(reader);
|
||||
Api.constrain(site, user);
|
||||
for (var i=0; i<feed.entries.size(); i+=1) {
|
||||
var entry = feed.entries.get(i);
|
||||
var category = entry.categories.get(0);
|
||||
if (category.name !== "http://schemas.google.com/blogger/2008/kind#post") {
|
||||
continue;
|
||||
}
|
||||
var story = Story.add({
|
||||
title: entry.title,
|
||||
text: entry.description || entry.contents.get(0).value,
|
||||
created: entry.publishedDate.format("yyyy-MM-dd HH:mm"),
|
||||
status: Story.CLOSED,
|
||||
mode: Story.FEATURED
|
||||
}, site, user);
|
||||
}
|
||||
} catch (ex) {
|
||||
app.log(ex);
|
||||
}
|
||||
File.remove.call(xml);
|
||||
}
|
||||
} catch (ex) {
|
||||
app.log(ex);
|
||||
}
|
||||
|
||||
// Reset the site’s export status
|
||||
site.job = null;
|
||||
site.import_id = null;
|
||||
return;
|
||||
// Reset the site’s export status
|
||||
site.job = null;
|
||||
site.import_id = null;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -13,14 +13,14 @@
|
|||
* @function
|
||||
* @param {Object} value Any JavaScript value, usually an object or array.
|
||||
* @param {Function|String[]} [replacer] An optional parameter that determines how object
|
||||
* values are stringified for objects. It can be a
|
||||
* function or an array of strings.
|
||||
* values are stringified for objects. It can be a
|
||||
* function or an array of strings.
|
||||
* @param {String|Number} [space] An optional parameter that specifies the indentation
|
||||
* of nested structures. If it is omitted, the text will
|
||||
* be packed without extra whitespace. If it is a number,
|
||||
* it will specify the number of spaces to indent at each
|
||||
* level. If it is a string (such as '\t' or ' '),
|
||||
* it contains the characters used to indent at each level.
|
||||
* of nested structures. If it is omitted, the text will
|
||||
* be packed without extra whitespace. If it is a number,
|
||||
* it will specify the number of spaces to indent at each
|
||||
* level. If it is a string (such as '\t' or ' '),
|
||||
* it contains the characters used to indent at each level.
|
||||
* @returns {String}
|
||||
*/
|
||||
|
||||
|
@ -39,160 +39,160 @@
|
|||
|
||||
|
||||
/*
|
||||
http://www.JSON.org/json2.js
|
||||
2011-02-23
|
||||
http://www.JSON.org/json2.js
|
||||
2011-02-23
|
||||
|
||||
Public Domain.
|
||||
Public Domain.
|
||||
|
||||
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
||||
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
||||
|
||||
See http://www.JSON.org/js.html
|
||||
See http://www.JSON.org/js.html
|
||||
|
||||
|
||||
This code should be minified before deployment.
|
||||
See http://javascript.crockford.com/jsmin.html
|
||||
This code should be minified before deployment.
|
||||
See http://javascript.crockford.com/jsmin.html
|
||||
|
||||
USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
|
||||
NOT CONTROL.
|
||||
USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
|
||||
NOT CONTROL.
|
||||
|
||||
|
||||
This file creates a global JSON object containing two methods: stringify
|
||||
and parse.
|
||||
This file creates a global JSON object containing two methods: stringify
|
||||
and parse.
|
||||
|
||||
JSON.stringify(value, replacer, space)
|
||||
value any JavaScript value, usually an object or array.
|
||||
JSON.stringify(value, replacer, space)
|
||||
value any JavaScript value, usually an object or array.
|
||||
|
||||
replacer an optional parameter that determines how object
|
||||
values are stringified for objects. It can be a
|
||||
function or an array of strings.
|
||||
replacer an optional parameter that determines how object
|
||||
values are stringified for objects. It can be a
|
||||
function or an array of strings.
|
||||
|
||||
space an optional parameter that specifies the indentation
|
||||
of nested structures. If it is omitted, the text will
|
||||
be packed without extra whitespace. If it is a number,
|
||||
it will specify the number of spaces to indent at each
|
||||
level. If it is a string (such as '\t' or ' '),
|
||||
it contains the characters used to indent at each level.
|
||||
space an optional parameter that specifies the indentation
|
||||
of nested structures. If it is omitted, the text will
|
||||
be packed without extra whitespace. If it is a number,
|
||||
it will specify the number of spaces to indent at each
|
||||
level. If it is a string (such as '\t' or ' '),
|
||||
it contains the characters used to indent at each level.
|
||||
|
||||
This method produces a JSON text from a JavaScript value.
|
||||
This method produces a JSON text from a JavaScript value.
|
||||
|
||||
When an object value is found, if the object contains a toJSON
|
||||
method, its toJSON method will be called and the result will be
|
||||
stringified. A toJSON method does not serialize: it returns the
|
||||
value represented by the name/value pair that should be serialized,
|
||||
or undefined if nothing should be serialized. The toJSON method
|
||||
will be passed the key associated with the value, and this will be
|
||||
bound to the value
|
||||
When an object value is found, if the object contains a toJSON
|
||||
method, its toJSON method will be called and the result will be
|
||||
stringified. A toJSON method does not serialize: it returns the
|
||||
value represented by the name/value pair that should be serialized,
|
||||
or undefined if nothing should be serialized. The toJSON method
|
||||
will be passed the key associated with the value, and this will be
|
||||
bound to the value
|
||||
|
||||
For example, this would serialize Dates as ISO strings.
|
||||
For example, this would serialize Dates as ISO strings.
|
||||
|
||||
Date.prototype.toJSON = function (key) {
|
||||
function f(n) {
|
||||
// Format integers to have at least two digits.
|
||||
return n < 10 ? '0' + n : n;
|
||||
}
|
||||
Date.prototype.toJSON = function (key) {
|
||||
function f(n) {
|
||||
// Format integers to have at least two digits.
|
||||
return n < 10 ? '0' + n : n;
|
||||
}
|
||||
|
||||
return this.getUTCFullYear() + '-' +
|
||||
f(this.getUTCMonth() + 1) + '-' +
|
||||
f(this.getUTCDate()) + 'T' +
|
||||
f(this.getUTCHours()) + ':' +
|
||||
f(this.getUTCMinutes()) + ':' +
|
||||
f(this.getUTCSeconds()) + 'Z';
|
||||
};
|
||||
return this.getUTCFullYear() + '-' +
|
||||
f(this.getUTCMonth() + 1) + '-' +
|
||||
f(this.getUTCDate()) + 'T' +
|
||||
f(this.getUTCHours()) + ':' +
|
||||
f(this.getUTCMinutes()) + ':' +
|
||||
f(this.getUTCSeconds()) + 'Z';
|
||||
};
|
||||
|
||||
You can provide an optional replacer method. It will be passed the
|
||||
key and value of each member, with this bound to the containing
|
||||
object. The value that is returned from your method will be
|
||||
serialized. If your method returns undefined, then the member will
|
||||
be excluded from the serialization.
|
||||
You can provide an optional replacer method. It will be passed the
|
||||
key and value of each member, with this bound to the containing
|
||||
object. The value that is returned from your method will be
|
||||
serialized. If your method returns undefined, then the member will
|
||||
be excluded from the serialization.
|
||||
|
||||
If the replacer parameter is an array of strings, then it will be
|
||||
used to select the members to be serialized. It filters the results
|
||||
such that only members with keys listed in the replacer array are
|
||||
stringified.
|
||||
If the replacer parameter is an array of strings, then it will be
|
||||
used to select the members to be serialized. It filters the results
|
||||
such that only members with keys listed in the replacer array are
|
||||
stringified.
|
||||
|
||||
Values that do not have JSON representations, such as undefined or
|
||||
functions, will not be serialized. Such values in objects will be
|
||||
dropped; in arrays they will be replaced with null. You can use
|
||||
a replacer function to replace those with JSON values.
|
||||
JSON.stringify(undefined) returns undefined.
|
||||
Values that do not have JSON representations, such as undefined or
|
||||
functions, will not be serialized. Such values in objects will be
|
||||
dropped; in arrays they will be replaced with null. You can use
|
||||
a replacer function to replace those with JSON values.
|
||||
JSON.stringify(undefined) returns undefined.
|
||||
|
||||
The optional space parameter produces a stringification of the
|
||||
value that is filled with line breaks and indentation to make it
|
||||
easier to read.
|
||||
The optional space parameter produces a stringification of the
|
||||
value that is filled with line breaks and indentation to make it
|
||||
easier to read.
|
||||
|
||||
If the space parameter is a non-empty string, then that string will
|
||||
be used for indentation. If the space parameter is a number, then
|
||||
the indentation will be that many spaces.
|
||||
If the space parameter is a non-empty string, then that string will
|
||||
be used for indentation. If the space parameter is a number, then
|
||||
the indentation will be that many spaces.
|
||||
|
||||
Example:
|
||||
Example:
|
||||
|
||||
text = JSON.stringify(['e', {pluribus: 'unum'}]);
|
||||
// text is '["e",{"pluribus":"unum"}]'
|
||||
text = JSON.stringify(['e', {pluribus: 'unum'}]);
|
||||
// text is '["e",{"pluribus":"unum"}]'
|
||||
|
||||
|
||||
text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
|
||||
// text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
|
||||
text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
|
||||
// text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
|
||||
|
||||
text = JSON.stringify([new Date()], function (key, value) {
|
||||
return this[key] instanceof Date ?
|
||||
'Date(' + this[key] + ')' : value;
|
||||
});
|
||||
// text is '["Date(---current time---)"]'
|
||||
text = JSON.stringify([new Date()], function (key, value) {
|
||||
return this[key] instanceof Date ?
|
||||
'Date(' + this[key] + ')' : value;
|
||||
});
|
||||
// text is '["Date(---current time---)"]'
|
||||
|
||||
|
||||
JSON.parse(text, reviver)
|
||||
This method parses a JSON text to produce an object or array.
|
||||
It can throw a SyntaxError exception.
|
||||
JSON.parse(text, reviver)
|
||||
This method parses a JSON text to produce an object or array.
|
||||
It can throw a SyntaxError exception.
|
||||
|
||||
The optional reviver parameter is a function that can filter and
|
||||
transform the results. It receives each of the keys and values,
|
||||
and its return value is used instead of the original value.
|
||||
If it returns what it received, then the structure is not modified.
|
||||
If it returns undefined then the member is deleted.
|
||||
The optional reviver parameter is a function that can filter and
|
||||
transform the results. It receives each of the keys and values,
|
||||
and its return value is used instead of the original value.
|
||||
If it returns what it received, then the structure is not modified.
|
||||
If it returns undefined then the member is deleted.
|
||||
|
||||
Example:
|
||||
Example:
|
||||
|
||||
// Parse the text. Values that look like ISO date strings will
|
||||
// be converted to Date objects.
|
||||
// Parse the text. Values that look like ISO date strings will
|
||||
// be converted to Date objects.
|
||||
|
||||
myData = JSON.parse(text, function (key, value) {
|
||||
var a;
|
||||
if (typeof value === 'string') {
|
||||
a =
|
||||
myData = JSON.parse(text, function (key, value) {
|
||||
var a;
|
||||
if (typeof value === 'string') {
|
||||
a =
|
||||
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
|
||||
if (a) {
|
||||
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
|
||||
+a[5], +a[6]));
|
||||
}
|
||||
}
|
||||
return value;
|
||||
});
|
||||
if (a) {
|
||||
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
|
||||
+a[5], +a[6]));
|
||||
}
|
||||
}
|
||||
return value;
|
||||
});
|
||||
|
||||
myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
|
||||
var d;
|
||||
if (typeof value === 'string' &&
|
||||
value.slice(0, 5) === 'Date(' &&
|
||||
value.slice(-1) === ')') {
|
||||
d = new Date(value.slice(5, -1));
|
||||
if (d) {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
});
|
||||
myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
|
||||
var d;
|
||||
if (typeof value === 'string' &&
|
||||
value.slice(0, 5) === 'Date(' &&
|
||||
value.slice(-1) === ')') {
|
||||
d = new Date(value.slice(5, -1));
|
||||
if (d) {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
});
|
||||
|
||||
|
||||
This is a reference implementation. You are free to copy, modify, or
|
||||
redistribute.
|
||||
This is a reference implementation. You are free to copy, modify, or
|
||||
redistribute.
|
||||
*/
|
||||
|
||||
/*jslint evil: true, strict: false, regexp: false */
|
||||
|
||||
/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
|
||||
call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
|
||||
getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
|
||||
lastIndex, length, parse, prototype, push, replace, slice, stringify,
|
||||
test, toJSON, toString, valueOf
|
||||
call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
|
||||
getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
|
||||
lastIndex, length, parse, prototype, push, replace, slice, stringify,
|
||||
test, toJSON, toString, valueOf
|
||||
*/
|
||||
|
||||
|
||||
|
@ -201,197 +201,197 @@
|
|||
|
||||
var JSON;
|
||||
if (!JSON) {
|
||||
JSON = {};
|
||||
JSON = {};
|
||||
}
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
"use strict";
|
||||
|
||||
function f(n) {
|
||||
// Format integers to have at least two digits.
|
||||
return n < 10 ? '0' + n : n;
|
||||
}
|
||||
function f(n) {
|
||||
// Format integers to have at least two digits.
|
||||
return n < 10 ? '0' + n : n;
|
||||
}
|
||||
|
||||
if (typeof Date.prototype.toJSON !== 'function') {
|
||||
if (typeof Date.prototype.toJSON !== 'function') {
|
||||
|
||||
Date.prototype.toJSON = function (key) {
|
||||
Date.prototype.toJSON = function (key) {
|
||||
|
||||
return isFinite(this.valueOf()) ?
|
||||
this.getUTCFullYear() + '-' +
|
||||
f(this.getUTCMonth() + 1) + '-' +
|
||||
f(this.getUTCDate()) + 'T' +
|
||||
f(this.getUTCHours()) + ':' +
|
||||
f(this.getUTCMinutes()) + ':' +
|
||||
f(this.getUTCSeconds()) + 'Z' : null;
|
||||
return isFinite(this.valueOf()) ?
|
||||
this.getUTCFullYear() + '-' +
|
||||
f(this.getUTCMonth() + 1) + '-' +
|
||||
f(this.getUTCDate()) + 'T' +
|
||||
f(this.getUTCHours()) + ':' +
|
||||
f(this.getUTCMinutes()) + ':' +
|
||||
f(this.getUTCSeconds()) + 'Z' : null;
|
||||
};
|
||||
|
||||
String.prototype.toJSON =
|
||||
Number.prototype.toJSON =
|
||||
Boolean.prototype.toJSON = function (key) {
|
||||
return this.valueOf();
|
||||
};
|
||||
}
|
||||
|
||||
String.prototype.toJSON =
|
||||
Number.prototype.toJSON =
|
||||
Boolean.prototype.toJSON = function (key) {
|
||||
return this.valueOf();
|
||||
};
|
||||
}
|
||||
|
||||
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
||||
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
||||
gap,
|
||||
indent,
|
||||
meta = { // table of character substitutions
|
||||
'\b': '\\b',
|
||||
'\t': '\\t',
|
||||
'\n': '\\n',
|
||||
'\f': '\\f',
|
||||
'\r': '\\r',
|
||||
'"' : '\\"',
|
||||
'\\': '\\\\'
|
||||
},
|
||||
rep;
|
||||
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
||||
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
||||
gap,
|
||||
indent,
|
||||
meta = { // table of character substitutions
|
||||
'\b': '\\b',
|
||||
'\t': '\\t',
|
||||
'\n': '\\n',
|
||||
'\f': '\\f',
|
||||
'\r': '\\r',
|
||||
'"' : '\\"',
|
||||
'\\': '\\\\'
|
||||
},
|
||||
rep;
|
||||
|
||||
|
||||
function quote(string) {
|
||||
function quote(string) {
|
||||
|
||||
// If the string contains no control characters, no quote characters, and no
|
||||
// backslash characters, then we can safely slap some quotes around it.
|
||||
// Otherwise we must also replace the offending characters with safe escape
|
||||
// sequences.
|
||||
|
||||
escapable.lastIndex = 0;
|
||||
return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
|
||||
var c = meta[a];
|
||||
return typeof c === 'string' ? c :
|
||||
'\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
||||
}) + '"' : '"' + string + '"';
|
||||
}
|
||||
escapable.lastIndex = 0;
|
||||
return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
|
||||
var c = meta[a];
|
||||
return typeof c === 'string' ? c :
|
||||
'\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
||||
}) + '"' : '"' + string + '"';
|
||||
}
|
||||
|
||||
|
||||
function str(key, holder) {
|
||||
function str(key, holder) {
|
||||
|
||||
// Produce a string from holder[key].
|
||||
|
||||
var i, // The loop counter.
|
||||
k, // The member key.
|
||||
v, // The member value.
|
||||
length,
|
||||
mind = gap,
|
||||
partial,
|
||||
value = holder[key];
|
||||
var i, // The loop counter.
|
||||
k, // The member key.
|
||||
v, // The member value.
|
||||
length,
|
||||
mind = gap,
|
||||
partial,
|
||||
value = holder[key];
|
||||
|
||||
// If the value has a toJSON method, call it to obtain a replacement value.
|
||||
|
||||
if (value && typeof value === 'object' &&
|
||||
typeof value.toJSON === 'function') {
|
||||
value = value.toJSON(key);
|
||||
}
|
||||
if (value && typeof value === 'object' &&
|
||||
typeof value.toJSON === 'function') {
|
||||
value = value.toJSON(key);
|
||||
}
|
||||
|
||||
// If we were called with a replacer function, then call the replacer to
|
||||
// obtain a replacement value.
|
||||
|
||||
if (typeof rep === 'function') {
|
||||
value = rep.call(holder, key, value);
|
||||
}
|
||||
if (typeof rep === 'function') {
|
||||
value = rep.call(holder, key, value);
|
||||
}
|
||||
|
||||
// What happens next depends on the value's type.
|
||||
|
||||
switch (typeof value) {
|
||||
case 'string':
|
||||
return quote(value);
|
||||
switch (typeof value) {
|
||||
case 'string':
|
||||
return quote(value);
|
||||
|
||||
case 'number':
|
||||
case 'number':
|
||||
|
||||
// JSON numbers must be finite. Encode non-finite numbers as null.
|
||||
|
||||
return isFinite(value) ? String(value) : 'null';
|
||||
return isFinite(value) ? String(value) : 'null';
|
||||
|
||||
case 'boolean':
|
||||
case 'null':
|
||||
case 'boolean':
|
||||
case 'null':
|
||||
|
||||
// If the value is a boolean or null, convert it to a string. Note:
|
||||
// typeof null does not produce 'null'. The case is included here in
|
||||
// the remote chance that this gets fixed someday.
|
||||
|
||||
return String(value);
|
||||
return String(value);
|
||||
|
||||
// If the type is 'object', we might be dealing with an object or an array or
|
||||
// null.
|
||||
|
||||
case 'object':
|
||||
case 'object':
|
||||
|
||||
// Due to a specification blunder in ECMAScript, typeof null is 'object',
|
||||
// so watch out for that case.
|
||||
|
||||
if (!value) {
|
||||
return 'null';
|
||||
}
|
||||
if (!value) {
|
||||
return 'null';
|
||||
}
|
||||
|
||||
// Make an array to hold the partial results of stringifying this object value.
|
||||
|
||||
gap += indent;
|
||||
partial = [];
|
||||
gap += indent;
|
||||
partial = [];
|
||||
|
||||
// Is the value an array?
|
||||
|
||||
if (Object.prototype.toString.apply(value) === '[object Array]') {
|
||||
if (Object.prototype.toString.apply(value) === '[object Array]') {
|
||||
|
||||
// The value is an array. Stringify every element. Use null as a placeholder
|
||||
// for non-JSON values.
|
||||
|
||||
length = value.length;
|
||||
for (i = 0; i < length; i += 1) {
|
||||
partial[i] = str(i, value) || 'null';
|
||||
}
|
||||
length = value.length;
|
||||
for (i = 0; i < length; i += 1) {
|
||||
partial[i] = str(i, value) || 'null';
|
||||
}
|
||||
|
||||
// Join all of the elements together, separated with commas, and wrap them in
|
||||
// brackets.
|
||||
|
||||
v = partial.length === 0 ? '[]' : gap ?
|
||||
'[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
|
||||
'[' + partial.join(',') + ']';
|
||||
gap = mind;
|
||||
return v;
|
||||
}
|
||||
v = partial.length === 0 ? '[]' : gap ?
|
||||
'[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
|
||||
'[' + partial.join(',') + ']';
|
||||
gap = mind;
|
||||
return v;
|
||||
}
|
||||
|
||||
// If the replacer is an array, use it to select the members to be stringified.
|
||||
|
||||
if (rep && typeof rep === 'object') {
|
||||
length = rep.length;
|
||||
for (i = 0; i < length; i += 1) {
|
||||
if (typeof rep[i] === 'string') {
|
||||
k = rep[i];
|
||||
v = str(k, value);
|
||||
if (v) {
|
||||
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
||||
}
|
||||
}
|
||||
if (rep && typeof rep === 'object') {
|
||||
length = rep.length;
|
||||
for (i = 0; i < length; i += 1) {
|
||||
if (typeof rep[i] === 'string') {
|
||||
k = rep[i];
|
||||
v = str(k, value);
|
||||
if (v) {
|
||||
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
// Otherwise, iterate through all of the keys in the object.
|
||||
|
||||
for (k in value) {
|
||||
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
||||
v = str(k, value);
|
||||
if (v) {
|
||||
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
||||
}
|
||||
}
|
||||
for (k in value) {
|
||||
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
||||
v = str(k, value);
|
||||
if (v) {
|
||||
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Join all of the member texts together, separated with commas,
|
||||
// and wrap them in braces.
|
||||
|
||||
v = partial.length === 0 ? '{}' : gap ?
|
||||
'{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
|
||||
'{' + partial.join(',') + '}';
|
||||
gap = mind;
|
||||
return v;
|
||||
}
|
||||
}
|
||||
v = partial.length === 0 ? '{}' : gap ?
|
||||
'{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
|
||||
'{' + partial.join(',') + '}';
|
||||
gap = mind;
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
// If the JSON object does not yet have a stringify method, give it one.
|
||||
|
||||
if (typeof JSON.stringify !== 'function') {
|
||||
JSON.stringify = function (value, replacer, space) {
|
||||
if (typeof JSON.stringify !== 'function') {
|
||||
JSON.stringify = function (value, replacer, space) {
|
||||
|
||||
// The stringify method takes a value and an optional replacer, and an optional
|
||||
// space parameter, and returns a JSON text. The replacer can be a function
|
||||
|
@ -399,86 +399,86 @@ if (!JSON) {
|
|||
// A default replacer method can be provided. Use of the space parameter can
|
||||
// produce text that is more easily readable.
|
||||
|
||||
var i;
|
||||
gap = '';
|
||||
indent = '';
|
||||
var i;
|
||||
gap = '';
|
||||
indent = '';
|
||||
|
||||
// If the space parameter is a number, make an indent string containing that
|
||||
// many spaces.
|
||||
|
||||
if (typeof space === 'number') {
|
||||
for (i = 0; i < space; i += 1) {
|
||||
indent += ' ';
|
||||
}
|
||||
if (typeof space === 'number') {
|
||||
for (i = 0; i < space; i += 1) {
|
||||
indent += ' ';
|
||||
}
|
||||
|
||||
// If the space parameter is a string, it will be used as the indent string.
|
||||
|
||||
} else if (typeof space === 'string') {
|
||||
indent = space;
|
||||
}
|
||||
} else if (typeof space === 'string') {
|
||||
indent = space;
|
||||
}
|
||||
|
||||
// If there is a replacer, it must be a function or an array.
|
||||
// Otherwise, throw an error.
|
||||
|
||||
rep = replacer;
|
||||
if (replacer && typeof replacer !== 'function' &&
|
||||
(typeof replacer !== 'object' ||
|
||||
typeof replacer.length !== 'number')) {
|
||||
throw new Error('JSON.stringify');
|
||||
}
|
||||
rep = replacer;
|
||||
if (replacer && typeof replacer !== 'function' &&
|
||||
(typeof replacer !== 'object' ||
|
||||
typeof replacer.length !== 'number')) {
|
||||
throw new Error('JSON.stringify');
|
||||
}
|
||||
|
||||
// Make a fake root object containing our value under the key of ''.
|
||||
// Return the result of stringifying the value.
|
||||
|
||||
return str('', {'': value});
|
||||
};
|
||||
}
|
||||
return str('', {'': value});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// If the JSON object does not yet have a parse method, give it one.
|
||||
|
||||
if (typeof JSON.parse !== 'function') {
|
||||
JSON.parse = function (text, reviver) {
|
||||
if (typeof JSON.parse !== 'function') {
|
||||
JSON.parse = function (text, reviver) {
|
||||
|
||||
// The parse method takes a text and an optional reviver function, and returns
|
||||
// a JavaScript value if the text is a valid JSON text.
|
||||
|
||||
var j;
|
||||
var j;
|
||||
|
||||
function walk(holder, key) {
|
||||
function walk(holder, key) {
|
||||
|
||||
// The walk method is used to recursively walk the resulting structure so
|
||||
// that modifications can be made.
|
||||
|
||||
var k, v, value = holder[key];
|
||||
if (value && typeof value === 'object') {
|
||||
for (k in value) {
|
||||
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
||||
v = walk(value, k);
|
||||
if (v !== undefined) {
|
||||
value[k] = v;
|
||||
} else {
|
||||
delete value[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
var k, v, value = holder[key];
|
||||
if (value && typeof value === 'object') {
|
||||
for (k in value) {
|
||||
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
||||
v = walk(value, k);
|
||||
if (v !== undefined) {
|
||||
value[k] = v;
|
||||
} else {
|
||||
delete value[k];
|
||||
}
|
||||
}
|
||||
return reviver.call(holder, key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return reviver.call(holder, key, value);
|
||||
}
|
||||
|
||||
|
||||
// Parsing happens in four stages. In the first stage, we replace certain
|
||||
// Unicode characters with escape sequences. JavaScript handles many characters
|
||||
// incorrectly, either silently deleting them, or treating them as line endings.
|
||||
|
||||
text = String(text);
|
||||
cx.lastIndex = 0;
|
||||
if (cx.test(text)) {
|
||||
text = text.replace(cx, function (a) {
|
||||
return '\\u' +
|
||||
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
||||
});
|
||||
}
|
||||
text = String(text);
|
||||
cx.lastIndex = 0;
|
||||
if (cx.test(text)) {
|
||||
text = text.replace(cx, function (a) {
|
||||
return '\\u' +
|
||||
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
||||
});
|
||||
}
|
||||
|
||||
// In the second stage, we run the text against regular expressions that look
|
||||
// for non-JSON patterns. We are especially concerned with '()' and 'new'
|
||||
|
@ -493,30 +493,30 @@ if (!JSON) {
|
|||
// we look to see that the remaining characters are only whitespace or ']' or
|
||||
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
|
||||
|
||||
if (/^[\],:{}\s]*$/
|
||||
.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
|
||||
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
|
||||
.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
||||
if (/^[\],:{}\s]*$/
|
||||
.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
|
||||
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
|
||||
.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
||||
|
||||
// In the third stage we use the eval function to compile the text into a
|
||||
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
|
||||
// in JavaScript: it can begin a block or an object literal. We wrap the text
|
||||
// in parens to eliminate the ambiguity.
|
||||
|
||||
j = eval('(' + text + ')');
|
||||
j = eval('(' + text + ')');
|
||||
|
||||
// In the optional fourth stage, we recursively walk the new structure, passing
|
||||
// each name/value pair to a reviver function for possible transformation.
|
||||
|
||||
return typeof reviver === 'function' ?
|
||||
walk({'': j}, '') : j;
|
||||
}
|
||||
return typeof reviver === 'function' ?
|
||||
walk({'': j}, '') : j;
|
||||
}
|
||||
|
||||
// If the text is not JSON parseable, then a SyntaxError is thrown.
|
||||
|
||||
throw new SyntaxError('JSON.parse');
|
||||
};
|
||||
}
|
||||
throw new SyntaxError('JSON.parse');
|
||||
};
|
||||
}
|
||||
}());
|
||||
|
||||
// Do not enumerate the new JSON methods.
|
||||
|
@ -530,10 +530,10 @@ Object.prototype.dontEnum("parseJSON");
|
|||
* @param {Object} data An arbitrary JavaScript object
|
||||
*/
|
||||
JSON.pad = function(data, callback) {
|
||||
if (!callback) {
|
||||
return;
|
||||
}
|
||||
return callback + "(" + JSON.stringify(data) + ")";
|
||||
if (!callback) {
|
||||
return;
|
||||
}
|
||||
return callback + "(" + JSON.stringify(data) + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -544,11 +544,11 @@ JSON.pad = function(data, callback) {
|
|||
* @param {Boolean} resume Switch to define whether further processing should be continued or not
|
||||
*/
|
||||
JSON.sendPaddedResponse = function(data, key, resume) {
|
||||
var callback = req.data[key || "callback"];
|
||||
if (callback) {
|
||||
res.contentType = "text/javascript";
|
||||
res.write(JSON.pad(data, callback));
|
||||
resume || res.stop();
|
||||
}
|
||||
return;
|
||||
var callback = req.data[key || "callback"];
|
||||
if (callback) {
|
||||
res.contentType = "text/javascript";
|
||||
res.write(JSON.pad(data, callback));
|
||||
resume || res.stop();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
|
@ -31,131 +31,131 @@
|
|||
* @constructor
|
||||
*/
|
||||
var Sql = function(options) {
|
||||
options || (options = {});
|
||||
var db = getDBConnection("antville");
|
||||
var query;
|
||||
options || (options = {});
|
||||
var db = getDBConnection("antville");
|
||||
var query;
|
||||
|
||||
var log = new function() {
|
||||
var fname = getProperty("sqlLog", "helma." + app.getName() + ".sql");
|
||||
return Packages.org.apache.commons.logging.LogFactory.getLog(fname);
|
||||
}
|
||||
var log = new function() {
|
||||
var fname = getProperty("sqlLog", "helma." + app.getName() + ".sql");
|
||||
return Packages.org.apache.commons.logging.LogFactory.getLog(fname);
|
||||
}
|
||||
|
||||
var SqlData = function(result) {
|
||||
var columns = [];
|
||||
this.values = {};
|
||||
var SqlData = function(result) {
|
||||
var columns = [];
|
||||
this.values = {};
|
||||
|
||||
for (var i=1; i<=result.getColumnCount(); i+=1) {
|
||||
columns.push(result.getColumnName(i).toLowerCase());
|
||||
}
|
||||
for (var i=1; i<=result.getColumnCount(); i+=1) {
|
||||
columns.push(result.getColumnName(i).toLowerCase());
|
||||
}
|
||||
|
||||
this.next = function() {
|
||||
for each (var key in columns) {
|
||||
this.values[key] = result.getColumnItem(key);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
var quote = function(str) {
|
||||
if (!options.quote || str === null) {
|
||||
return str;
|
||||
}
|
||||
return str.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
||||
}
|
||||
|
||||
var value = function(obj) {
|
||||
if (obj === null) {
|
||||
return obj;
|
||||
}
|
||||
if (obj === undefined) {
|
||||
obj = String(obj);
|
||||
}
|
||||
switch (obj.constructor) {
|
||||
case Number:
|
||||
return obj;
|
||||
case String:
|
||||
return quote(obj);
|
||||
case Date:
|
||||
return "from_unixtime(" + (obj.getTime() / 1000) + ")";
|
||||
case HopObject:
|
||||
case Object:
|
||||
return quote(obj.toSource());
|
||||
}
|
||||
return quote(String(obj));
|
||||
}
|
||||
|
||||
var resolve = function(args) {
|
||||
var sql = args[0];
|
||||
if (args.length > 1) {
|
||||
var values = Array.prototype.splice.call(args, 1);
|
||||
if (typeof values[0] === "object") {
|
||||
values = values[0];
|
||||
}
|
||||
sql = sql.replace(/\$(\w*)/g, function() {
|
||||
return value(values[arguments[1]]);
|
||||
});
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes an SQL command.
|
||||
* @param {String} sql The SQL command.
|
||||
* @returns {Object} The result of the SQL command.
|
||||
*/
|
||||
this.execute = function(sql) {
|
||||
sql = resolve(arguments);
|
||||
log.info(sql);
|
||||
if (options.test) {
|
||||
return app.log(sql);
|
||||
}
|
||||
var error;
|
||||
var result = db.executeCommand(sql);
|
||||
if (error = db.getLastError()) {
|
||||
app.log(error);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves an SQL query.
|
||||
* @example sql.retrieve('select $1 from $2 order by $1', 'date', 'foo')
|
||||
* ===> 'select date from foo order by date'
|
||||
* @returns {String}
|
||||
*/
|
||||
this.retrieve = function() {
|
||||
return log.info(query = resolve(arguments));
|
||||
}
|
||||
|
||||
/**
|
||||
* Traverses over the results of an SQL query.
|
||||
* @param {Function} callback The callback function executed for each record.
|
||||
*/
|
||||
this.traverse = function(callback) {
|
||||
var rows = db.executeRetrieval(query);
|
||||
if (rows && rows.next()) {
|
||||
do {
|
||||
var sql = new SqlData(rows);
|
||||
sql.next();
|
||||
if (!options.test) {
|
||||
callback.call(sql.values, rows);
|
||||
}
|
||||
} while (record = rows.next());
|
||||
rows.release();
|
||||
this.next = function() {
|
||||
for each (var key in columns) {
|
||||
this.values[key] = result.getColumnItem(key);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {String}
|
||||
*/
|
||||
this.toString = function() {
|
||||
return query;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
return this;
|
||||
var quote = function(str) {
|
||||
if (!options.quote || str === null) {
|
||||
return str;
|
||||
}
|
||||
return str.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
||||
}
|
||||
|
||||
var value = function(obj) {
|
||||
if (obj === null) {
|
||||
return obj;
|
||||
}
|
||||
if (obj === undefined) {
|
||||
obj = String(obj);
|
||||
}
|
||||
switch (obj.constructor) {
|
||||
case Number:
|
||||
return obj;
|
||||
case String:
|
||||
return quote(obj);
|
||||
case Date:
|
||||
return "from_unixtime(" + (obj.getTime() / 1000) + ")";
|
||||
case HopObject:
|
||||
case Object:
|
||||
return quote(obj.toSource());
|
||||
}
|
||||
return quote(String(obj));
|
||||
}
|
||||
|
||||
var resolve = function(args) {
|
||||
var sql = args[0];
|
||||
if (args.length > 1) {
|
||||
var values = Array.prototype.splice.call(args, 1);
|
||||
if (typeof values[0] === "object") {
|
||||
values = values[0];
|
||||
}
|
||||
sql = sql.replace(/\$(\w*)/g, function() {
|
||||
return value(values[arguments[1]]);
|
||||
});
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes an SQL command.
|
||||
* @param {String} sql The SQL command.
|
||||
* @returns {Object} The result of the SQL command.
|
||||
*/
|
||||
this.execute = function(sql) {
|
||||
sql = resolve(arguments);
|
||||
log.info(sql);
|
||||
if (options.test) {
|
||||
return app.log(sql);
|
||||
}
|
||||
var error;
|
||||
var result = db.executeCommand(sql);
|
||||
if (error = db.getLastError()) {
|
||||
app.log(error);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves an SQL query.
|
||||
* @example sql.retrieve('select $1 from $2 order by $1', 'date', 'foo')
|
||||
* ===> 'select date from foo order by date'
|
||||
* @returns {String}
|
||||
*/
|
||||
this.retrieve = function() {
|
||||
return log.info(query = resolve(arguments));
|
||||
}
|
||||
|
||||
/**
|
||||
* Traverses over the results of an SQL query.
|
||||
* @param {Function} callback The callback function executed for each record.
|
||||
*/
|
||||
this.traverse = function(callback) {
|
||||
var rows = db.executeRetrieval(query);
|
||||
if (rows && rows.next()) {
|
||||
do {
|
||||
var sql = new SqlData(rows);
|
||||
sql.next();
|
||||
if (!options.test) {
|
||||
callback.call(sql.values, rows);
|
||||
}
|
||||
} while (record = rows.next());
|
||||
rows.release();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {String}
|
||||
*/
|
||||
this.toString = function() {
|
||||
return query;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -169,47 +169,47 @@ Sql.COUNT = "select count(*) as count from $0";
|
|||
* @constant
|
||||
*/
|
||||
Sql.REFERRERS = "select referrer, count(*) as requests from " +
|
||||
"log where context_type = '$0' and context_id = $1 and action = " +
|
||||
"'main' and created > now() - interval '2 days' group " +
|
||||
"by referrer order by requests desc, referrer asc";
|
||||
"log where context_type = '$0' and context_id = $1 and action = " +
|
||||
"'main' and created > now() - interval '2 days' group " +
|
||||
"by referrer order by requests desc, referrer asc";
|
||||
|
||||
/**
|
||||
* SQL command for deleting all log entries older than 2 days.
|
||||
* @constant
|
||||
*/
|
||||
Sql.PURGEREFERRERS = "delete from log where action = 'main' and " +
|
||||
"created < now() - interval '2 days'";
|
||||
"created < now() - interval '2 days'";
|
||||
|
||||
/**
|
||||
* SQL query for searching stories and comments.
|
||||
* @constant
|
||||
*/
|
||||
Sql.SEARCH = "select content.id from content, site, metadata where site.id = $0 and " +
|
||||
"site.id = content.site_id and content.status in ('public', 'shared', 'open') and " +
|
||||
"content.id = metadata.parent_id and metadata.name in ('title', 'text') and " +
|
||||
"lower(metadata.value) like lower('%$1%') group by content.id, content.created " +
|
||||
"order by content.created desc limit $2";
|
||||
"site.id = content.site_id and content.status in ('public', 'shared', 'open') and " +
|
||||
"content.id = metadata.parent_id and metadata.name in ('title', 'text') and " +
|
||||
"lower(metadata.value) like lower('%$1%') group by content.id, content.created " +
|
||||
"order by content.created desc limit $2";
|
||||
|
||||
/**
|
||||
* SQL query for searching members.
|
||||
* @constant
|
||||
*/
|
||||
Sql.MEMBERSEARCH = "select name from account where name $0 '$1' " +
|
||||
"order by name asc limit $2";
|
||||
"order by name asc limit $2";
|
||||
|
||||
/**
|
||||
* SQL query for retrieving all story IDs in a site’s archive.
|
||||
* @constant
|
||||
*/
|
||||
Sql.ARCHIVE = "select id from content where site_id = $0 and prototype = 'Story' and " +
|
||||
"status in ('public', 'shared', 'open') $1 $2 limit $3 offset $4";
|
||||
"status in ('public', 'shared', 'open') $1 $2 limit $3 offset $4";
|
||||
|
||||
/**
|
||||
* SQL command for retrieving the size of a site’s archive.
|
||||
* @constant
|
||||
*/
|
||||
Sql.ARCHIVESIZE = "select count(*) as count from content where site_id = $0 " +
|
||||
"and prototype = 'Story' and status in ('public', 'shared', 'open') $1";
|
||||
"and prototype = 'Story' and status in ('public', 'shared', 'open') $1";
|
||||
|
||||
/**
|
||||
* SQL part filtering the archive query.
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
|
@ -27,62 +27,62 @@ app.addRepository("modules/helma/Aspects.js");
|
|||
|
||||
(function() {
|
||||
|
||||
function skinMayDisplayEditLink(name) {
|
||||
return req.cookies[User.COOKIE + 'LayoutSandbox'] &&
|
||||
res.handlers.layout.getPermission('main') &&
|
||||
typeof name === 'string' &&
|
||||
!name.startsWith('$') &&
|
||||
res.contentType === 'text/html';
|
||||
}
|
||||
function skinMayDisplayEditLink(name) {
|
||||
return req.cookies[User.COOKIE + 'LayoutSandbox'] &&
|
||||
res.handlers.layout.getPermission('main') &&
|
||||
typeof name === 'string' &&
|
||||
!name.startsWith('$') &&
|
||||
res.contentType === 'text/html';
|
||||
}
|
||||
|
||||
function renderSkin(args, func, object) {
|
||||
res.meta.skins || (res.meta.skins = {});
|
||||
function renderSkin(args, func, object) {
|
||||
res.meta.skins || (res.meta.skins = {});
|
||||
|
||||
var name = args[0];
|
||||
if (name.startsWith('#')) {
|
||||
// Fix names using short form (ie. missing prototype)
|
||||
name = object.constructor.name + name;
|
||||
var name = args[0];
|
||||
if (name.startsWith('#')) {
|
||||
// Fix names using short form (ie. missing prototype)
|
||||
name = object.constructor.name + name;
|
||||
}
|
||||
var id = name.replace('#', '-').toLowerCase();
|
||||
|
||||
if (skinMayDisplayEditLink(name) && !res.meta.skins[name]) {
|
||||
res.meta.skins[name] = true;
|
||||
var parts = name.split('#');
|
||||
var prototype = parts[0];
|
||||
var skinName = parts[1];
|
||||
var skin = new Skin(prototype, skinName);
|
||||
res.writeln('<!-- Begin of #skin-' + id + ' -->');
|
||||
res.writeln('<div id="skin-' + id + '" class="skin" data-name="' +
|
||||
name + '" data-href="' + skin.href('edit') + '">');
|
||||
func.apply(object, args);
|
||||
res.writeln('</div>\n<!-- End of #skin-' + id + ' -->');
|
||||
} else {
|
||||
func.apply(object, args);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
function renderSkinAsString(args, func, object) {
|
||||
var name = args[0];
|
||||
if (skinMayDisplayEditLink(name)) {
|
||||
res.push();
|
||||
object.renderSkin.apply(object, args);
|
||||
return res.pop();
|
||||
}
|
||||
return func.apply(object, args);
|
||||
}
|
||||
|
||||
var prototypes = app.__app__.getPrototypes().toArray();
|
||||
for each (var prototype in prototypes) {
|
||||
if (prototype.name in global) {
|
||||
global[prototype.name].prototype.onCodeUpdate = function() {
|
||||
this.__renderSkin__ = this.renderSkin;
|
||||
this.__renderSkinAsString__ = this.renderSkinAsString;
|
||||
helma.aspects.addAround(this, 'renderSkin', renderSkin);
|
||||
helma.aspects.addAround(this, 'renderSkinAsString', renderSkinAsString);
|
||||
}
|
||||
var id = name.replace('#', '-').toLowerCase();
|
||||
|
||||
if (skinMayDisplayEditLink(name) && !res.meta.skins[name]) {
|
||||
res.meta.skins[name] = true;
|
||||
var parts = name.split('#');
|
||||
var prototype = parts[0];
|
||||
var skinName = parts[1];
|
||||
var skin = new Skin(prototype, skinName);
|
||||
res.writeln('<!-- Begin of #skin-' + id + ' -->');
|
||||
res.writeln('<div id="skin-' + id + '" class="skin" data-name="' +
|
||||
name + '" data-href="' + skin.href('edit') + '">');
|
||||
func.apply(object, args);
|
||||
res.writeln('</div>\n<!-- End of #skin-' + id + ' -->');
|
||||
} else {
|
||||
func.apply(object, args);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
function renderSkinAsString(args, func, object) {
|
||||
var name = args[0];
|
||||
if (skinMayDisplayEditLink(name)) {
|
||||
res.push();
|
||||
object.renderSkin.apply(object, args);
|
||||
return res.pop();
|
||||
}
|
||||
return func.apply(object, args);
|
||||
}
|
||||
|
||||
var prototypes = app.__app__.getPrototypes().toArray();
|
||||
for each (var prototype in prototypes) {
|
||||
if (prototype.name in global) {
|
||||
global[prototype.name].prototype.onCodeUpdate = function() {
|
||||
this.__renderSkin__ = this.renderSkin;
|
||||
this.__renderSkinAsString__ = this.renderSkinAsString;
|
||||
helma.aspects.addAround(this, 'renderSkin', renderSkin);
|
||||
helma.aspects.addAround(this, 'renderSkinAsString', renderSkinAsString);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}());
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
|
@ -35,29 +35,29 @@
|
|||
* @param {String} potFile The filename for the output POT file.
|
||||
*/
|
||||
Root.prototype.extractMessages = function(script, scanDirs, potFile) {
|
||||
var temp = {print: global.print, readFile: global.readFile};
|
||||
global.print = function(str) {app.log(str);}
|
||||
global.readFile = function(fpath, encoding) {
|
||||
res.push();
|
||||
var file = new helma.File(fpath);
|
||||
file.open({charset: encoding || "UTF-8"});
|
||||
var str;
|
||||
while ((str = file.readln()) !== null) {
|
||||
res.writeln(str);
|
||||
}
|
||||
file.close();
|
||||
return res.pop();
|
||||
}
|
||||
var args = ["-o", potFile, "-e", "utf-8"];
|
||||
for each (var dir in scanDirs.split(" ")) {
|
||||
args.push(app.dir + "/../" + dir);
|
||||
}
|
||||
var file = new helma.File(script);
|
||||
var MessageParser = new Function(file.readAll());
|
||||
MessageParser.apply(global, args);
|
||||
global.print = temp.print;
|
||||
global.readFile = temp.readFile;
|
||||
return;
|
||||
var temp = {print: global.print, readFile: global.readFile};
|
||||
global.print = function(str) {app.log(str);}
|
||||
global.readFile = function(fpath, encoding) {
|
||||
res.push();
|
||||
var file = new helma.File(fpath);
|
||||
file.open({charset: encoding || "UTF-8"});
|
||||
var str;
|
||||
while ((str = file.readln()) !== null) {
|
||||
res.writeln(str);
|
||||
}
|
||||
file.close();
|
||||
return res.pop();
|
||||
}
|
||||
var args = ["-o", potFile, "-e", "utf-8"];
|
||||
for each (var dir in scanDirs.split(" ")) {
|
||||
args.push(app.dir + "/../" + dir);
|
||||
}
|
||||
var file = new helma.File(script);
|
||||
var MessageParser = new Function(file.readAll());
|
||||
MessageParser.apply(global, args);
|
||||
global.print = temp.print;
|
||||
global.readFile = temp.readFile;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,9 +68,9 @@ Root.prototype.extractMessages = function(script, scanDirs, potFile) {
|
|||
* @returns {String}
|
||||
*/
|
||||
function cgettext(key, context) {
|
||||
var msgId = cgettext.getKey(key, context);
|
||||
var text = jala.i18n.translate(msgId);
|
||||
return text === msgId ? key : text;
|
||||
var msgId = cgettext.getKey(key, context);
|
||||
var text = jala.i18n.translate(msgId);
|
||||
return text === msgId ? key : text;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -81,7 +81,7 @@ function cgettext(key, context) {
|
|||
* @example cgettext.getKey('comment', 'verb') ===> 'comment // verb'
|
||||
*/
|
||||
cgettext.getKey = function(key, context) {
|
||||
return context ? key + " // " + context : key;
|
||||
return context ? key + " // " + context : key;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,18 +92,18 @@ cgettext.getKey = function(key, context) {
|
|||
* @see jala.i18n.gettext
|
||||
*/
|
||||
function gettext_macro(param, text /*, value1, value2, ...*/) {
|
||||
if (!text) {
|
||||
return;
|
||||
}
|
||||
var re = gettext_macro.REGEX;
|
||||
var args = [text.toString().replace(re, String.SPACE)];
|
||||
for (var i=2; i<arguments.length; i+=1) {
|
||||
args.push(arguments[i]);
|
||||
}
|
||||
if (param.context) {
|
||||
return cgettext.call(this, args[0], param.context);
|
||||
}
|
||||
return gettext.apply(this, args);
|
||||
if (!text) {
|
||||
return;
|
||||
}
|
||||
var re = gettext_macro.REGEX;
|
||||
var args = [text.toString().replace(re, String.SPACE)];
|
||||
for (var i=2; i<arguments.length; i+=1) {
|
||||
args.push(arguments[i]);
|
||||
}
|
||||
if (param.context) {
|
||||
return cgettext.call(this, args[0], param.context);
|
||||
}
|
||||
return gettext.apply(this, args);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -121,15 +121,15 @@ gettext_macro.REGEX = /\s+/g;
|
|||
* @see jala.i18n.ngettext
|
||||
*/
|
||||
function ngettext_macro(param, singular, plural /*, value1, value2, ...*/) {
|
||||
if (!singular || !plural) {
|
||||
return;
|
||||
}
|
||||
var re = gettext_macro.REGEX;
|
||||
var args = [singular.toString().replace(re, String.SPACE), plural.replace(re, String.SPACE)];
|
||||
for (var i=3; i<arguments.length; i+=1) {
|
||||
args.push(arguments[i]);
|
||||
}
|
||||
return ngettext.apply(this, args);
|
||||
if (!singular || !plural) {
|
||||
return;
|
||||
}
|
||||
var re = gettext_macro.REGEX;
|
||||
var args = [singular.toString().replace(re, String.SPACE), plural.replace(re, String.SPACE)];
|
||||
for (var i=3; i<arguments.length; i+=1) {
|
||||
args.push(arguments[i]);
|
||||
}
|
||||
return ngettext.apply(this, args);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -140,5 +140,5 @@ function ngettext_macro(param, singular, plural /*, value1, value2, ...*/) {
|
|||
* @see jala.i18n.markgettext
|
||||
*/
|
||||
function markgettext_macro(param, singular, plural) {
|
||||
return markgettext.call(this, singular, plural);
|
||||
return markgettext.call(this, singular, plural);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
||||
|
@ -37,19 +37,19 @@ app.addRepository('modules/helma/Aspects');
|
|||
* conditional checks of individual prototype’s remove() methods
|
||||
*/
|
||||
HopObject.remove = function(options) {
|
||||
var item;
|
||||
while (this.size() > 0) {
|
||||
item = this.get(0);
|
||||
if (item.constructor.remove) {
|
||||
item.constructor.remove.call(item, options);
|
||||
} else if (!options) {
|
||||
item.remove();
|
||||
} else {
|
||||
throw Error("Missing static " + item.constructor.name +
|
||||
".remove() method");
|
||||
}
|
||||
}
|
||||
return;
|
||||
var item;
|
||||
while (this.size() > 0) {
|
||||
item = this.get(0);
|
||||
if (item.constructor.remove) {
|
||||
item.constructor.remove.call(item, options);
|
||||
} else if (!options) {
|
||||
item.remove();
|
||||
} else {
|
||||
throw Error("Missing static " + item.constructor.name +
|
||||
".remove() method");
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,20 +58,20 @@ HopObject.remove = function(options) {
|
|||
* @param {HopObject} collection
|
||||
*/
|
||||
HopObject.getFromPath = function(name, collection) {
|
||||
if (name) {
|
||||
var site;
|
||||
if (name.contains("/")) {
|
||||
var parts = name.split("/");
|
||||
site = root.get(parts[0]);
|
||||
name = parts[1];
|
||||
} else {
|
||||
site = res.handlers.site;
|
||||
}
|
||||
if (site && site.getPermission("main")) {
|
||||
return site[collection].get(name);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
if (name) {
|
||||
var site;
|
||||
if (name.contains("/")) {
|
||||
var parts = name.split("/");
|
||||
site = root.get(parts[0]);
|
||||
name = parts[1];
|
||||
} else {
|
||||
site = res.handlers.site;
|
||||
}
|
||||
if (site && site.getPermission("main")) {
|
||||
return site[collection].get(name);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,21 +79,21 @@ HopObject.getFromPath = function(name, collection) {
|
|||
* should be replaced with static add() method.
|
||||
*/
|
||||
HopObject.confirmConstructor = function(ref) {
|
||||
var KEY = '__confirmedConstructors__';
|
||||
if (!res.meta[KEY]) {
|
||||
res.meta[KEY] = {};
|
||||
}
|
||||
var confirmed = res.meta[KEY];
|
||||
if (typeof ref === 'function') {
|
||||
confirmed[ref.name] = true;
|
||||
} else {
|
||||
ref = (ref || this).constructor.name;
|
||||
if (!confirmed[ref]) {
|
||||
app.logger.warn('Calling unconfirmed constructor for ' +
|
||||
ref + ' prototype – please check!');
|
||||
}
|
||||
}
|
||||
return;
|
||||
var KEY = '__confirmedConstructors__';
|
||||
if (!res.meta[KEY]) {
|
||||
res.meta[KEY] = {};
|
||||
}
|
||||
var confirmed = res.meta[KEY];
|
||||
if (typeof ref === 'function') {
|
||||
confirmed[ref.name] = true;
|
||||
} else {
|
||||
ref = (ref || this).constructor.name;
|
||||
if (!confirmed[ref]) {
|
||||
app.logger.warn('Calling unconfirmed constructor for ' +
|
||||
ref + ' prototype – please check!');
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -106,63 +106,63 @@ HopObject.confirmConstructor = function(ref) {
|
|||
*
|
||||
*/
|
||||
HopObject.prototype.onRequest = function() {
|
||||
// Checking if we are on the correct host to prevent at least some XSS issues
|
||||
if (req.action !== "notfound" && req.action !== "error" &&
|
||||
this.href().contains("://") &&
|
||||
!this.href().toLowerCase().startsWith(req.servletRequest.scheme +
|
||||
"://" + req.servletRequest.serverName.toLowerCase())) {
|
||||
res.redirect(this.href(req.action === "main" ? String.EMPTY : req.action));
|
||||
}
|
||||
// Checking if we are on the correct host to prevent at least some XSS issues
|
||||
if (req.action !== "notfound" && req.action !== "error" &&
|
||||
this.href().contains("://") &&
|
||||
!this.href().toLowerCase().startsWith(req.servletRequest.scheme +
|
||||
"://" + req.servletRequest.serverName.toLowerCase())) {
|
||||
res.redirect(this.href(req.action === "main" ? String.EMPTY : req.action));
|
||||
}
|
||||
|
||||
User.autoLogin();
|
||||
res.handlers.membership = User.getMembership();
|
||||
User.autoLogin();
|
||||
res.handlers.membership = User.getMembership();
|
||||
|
||||
if (User.getCurrentStatus() === User.BLOCKED) {
|
||||
session.data.status = 403;
|
||||
session.data.error = gettext("Your account has been blocked.") + String.SPACE +
|
||||
gettext("Please contact an administrator for further information.");
|
||||
User.logout();
|
||||
res.redirect(root.href("error"));
|
||||
}
|
||||
if (User.getCurrentStatus() === User.BLOCKED) {
|
||||
session.data.status = 403;
|
||||
session.data.error = gettext("Your account has been blocked.") + String.SPACE +
|
||||
gettext("Please contact an administrator for further information.");
|
||||
User.logout();
|
||||
res.redirect(root.href("error"));
|
||||
}
|
||||
|
||||
if (res.handlers.site.status === Site.BLOCKED &&
|
||||
!User.require(User.PRIVILEGED)) {
|
||||
session.data.status = 403;
|
||||
session.data.error = gettext("The site you requested has been blocked.") +
|
||||
String.SPACE + gettext("Please contact an administrator for further information.");
|
||||
res.redirect(root.href("error"));
|
||||
}
|
||||
if (res.handlers.site.status === Site.BLOCKED &&
|
||||
!User.require(User.PRIVILEGED)) {
|
||||
session.data.status = 403;
|
||||
session.data.error = gettext("The site you requested has been blocked.") +
|
||||
String.SPACE + gettext("Please contact an administrator for further information.");
|
||||
res.redirect(root.href("error"));
|
||||
}
|
||||
|
||||
HopObject.confirmConstructor(Layout);
|
||||
res.handlers.layout = res.handlers.site.layout || new Layout;
|
||||
res.skinpath = res.handlers.layout.getSkinPath();
|
||||
HopObject.confirmConstructor(Layout);
|
||||
res.handlers.layout = res.handlers.site.layout || new Layout;
|
||||
res.skinpath = res.handlers.layout.getSkinPath();
|
||||
|
||||
if (!this.getPermission(req.action)) {
|
||||
if (!session.user) {
|
||||
User.setLocation(root.href() + req.path);
|
||||
res.message = gettext("Please login first.");
|
||||
res.redirect(res.handlers.site.members.href("login"));
|
||||
}
|
||||
User.getLocation();
|
||||
res.status = 401;
|
||||
res.data.title = gettext("{0} 401 Error", root.title);
|
||||
res.data.body = root.renderSkinAsString("$Root#error", {error:
|
||||
gettext("You are not allowed to access this part of the site.")});
|
||||
res.handlers.site.renderSkin("Site#page");
|
||||
session.data.error = null;
|
||||
res.stop();
|
||||
}
|
||||
if (!this.getPermission(req.action)) {
|
||||
if (!session.user) {
|
||||
User.setLocation(root.href() + req.path);
|
||||
res.message = gettext("Please login first.");
|
||||
res.redirect(res.handlers.site.members.href("login"));
|
||||
}
|
||||
User.getLocation();
|
||||
res.status = 401;
|
||||
res.data.title = gettext("{0} 401 Error", root.title);
|
||||
res.data.body = root.renderSkinAsString("$Root#error", {error:
|
||||
gettext("You are not allowed to access this part of the site.")});
|
||||
res.handlers.site.renderSkin("Site#page");
|
||||
session.data.error = null;
|
||||
res.stop();
|
||||
}
|
||||
|
||||
res.meta.values = {};
|
||||
res.handlers.site.renderSkinAsString("Site#values");
|
||||
return;
|
||||
res.meta.values = {};
|
||||
res.handlers.site.renderSkinAsString("Site#values");
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns Boolean
|
||||
*/
|
||||
HopObject.prototype.getPermission = function() {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Marking some prototype names used in res.message of HopObject.delete_action()
|
||||
|
@ -174,45 +174,45 @@ markgettext("Poll");
|
|||
markgettext("Story");
|
||||
|
||||
HopObject.prototype.delete_action = function() {
|
||||
if (req.postParams.proceed) {
|
||||
try {
|
||||
var parent = this._parent;
|
||||
var url = this.constructor.remove.call(this, req.postParams) ||
|
||||
parent.href();
|
||||
res.message = gettext("{0} was successfully deleted.", gettext(this._prototype));
|
||||
res.redirect(User.getLocation() || url);
|
||||
} catch(ex) {
|
||||
res.message = ex;
|
||||
app.log(ex);
|
||||
}
|
||||
}
|
||||
if (req.postParams.proceed) {
|
||||
try {
|
||||
var parent = this._parent;
|
||||
var url = this.constructor.remove.call(this, req.postParams) ||
|
||||
parent.href();
|
||||
res.message = gettext("{0} was successfully deleted.", gettext(this._prototype));
|
||||
res.redirect(User.getLocation() || url);
|
||||
} catch(ex) {
|
||||
res.message = ex;
|
||||
app.log(ex);
|
||||
}
|
||||
}
|
||||
|
||||
res.data.action = this.href(req.action);
|
||||
res.data.title = gettext("Confirm Deletion");
|
||||
res.data.body = this.renderSkinAsString("$HopObject#confirm", {
|
||||
text: this.getConfirmText()
|
||||
});
|
||||
res.handlers.site.renderSkin("Site#page");
|
||||
return;
|
||||
res.data.action = this.href(req.action);
|
||||
res.data.title = gettext("Confirm Deletion");
|
||||
res.data.body = this.renderSkinAsString("$HopObject#confirm", {
|
||||
text: this.getConfirmText()
|
||||
});
|
||||
res.handlers.site.renderSkin("Site#page");
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Object}
|
||||
*/
|
||||
HopObject.prototype.touch = function() {
|
||||
return this.map({
|
||||
modified: new Date,
|
||||
modifier: session.user
|
||||
});
|
||||
return this.map({
|
||||
modified: new Date,
|
||||
modifier: session.user
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
HopObject.prototype.log = function() {
|
||||
var entry = new LogEntry(this, "main");
|
||||
app.data.entries.push(entry);
|
||||
return;
|
||||
var entry = new LogEntry(this, "main");
|
||||
app.data.entries.push(entry);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -220,79 +220,79 @@ HopObject.prototype.log = function() {
|
|||
* @param {String} action
|
||||
*/
|
||||
HopObject.prototype.notify = function(action) {
|
||||
var self = this;
|
||||
var site = res.handlers.site;
|
||||
var self = this;
|
||||
var site = res.handlers.site;
|
||||
|
||||
var getPermission = function(scope, mode, status) {
|
||||
if (scope === Admin.NONE || mode === Site.NOBODY ||
|
||||
status === Site.BLOCKED) {
|
||||
return false;
|
||||
}
|
||||
var scopes = [Admin.REGULAR, Admin.TRUSTED];
|
||||
if (scopes.indexOf(status) < scopes.indexOf(scope)) {
|
||||
return false;
|
||||
}
|
||||
if (!Membership.require(mode)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
var getPermission = function(scope, mode, status) {
|
||||
if (scope === Admin.NONE || mode === Site.NOBODY ||
|
||||
status === Site.BLOCKED) {
|
||||
return false;
|
||||
}
|
||||
var scopes = [Admin.REGULAR, Admin.TRUSTED];
|
||||
if (scopes.indexOf(status) < scopes.indexOf(scope)) {
|
||||
return false;
|
||||
}
|
||||
if (!Membership.require(mode)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Helper method for debugging
|
||||
var renderMatrix = function() {
|
||||
var buf = ['<table border=1 cellspacing=0>'];
|
||||
for each (var scope in Admin.getNotificationScopes()) {
|
||||
for each (var mode in Site.getNotificationModes()) {
|
||||
for each (var status in Site.getStatus()) {
|
||||
var perm = getPermission(scope.value, mode.value, status.value);
|
||||
buf.push('<tr style="');
|
||||
perm && buf.push('color: blue;');
|
||||
if (scope.value === root.notificationScope && mode.value ===
|
||||
site.notificationMode && status.value === site.status) {
|
||||
buf.push(' background-color: yellow;');
|
||||
}
|
||||
buf.push('">');
|
||||
buf.push('<td>', scope.value, '</td>');
|
||||
buf.push('<td>', status.value, '</td>');
|
||||
buf.push('<td>', mode.value, '</td>');
|
||||
buf.push('<td>', perm, '</td>');
|
||||
buf.push('</tr>');
|
||||
}
|
||||
}
|
||||
// Helper method for debugging
|
||||
var renderMatrix = function() {
|
||||
var buf = ['<table border=1 cellspacing=0>'];
|
||||
for each (var scope in Admin.getNotificationScopes()) {
|
||||
for each (var mode in Site.getNotificationModes()) {
|
||||
for each (var status in Site.getStatus()) {
|
||||
var perm = getPermission(scope.value, mode.value, status.value);
|
||||
buf.push('<tr style="');
|
||||
perm && buf.push('color: blue;');
|
||||
if (scope.value === |