Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom XSLT parameters. #4

Merged
merged 7 commits into from
Dec 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion FedoraGenericSearch/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<property name="javac.source" value="1.6"/>
<property name="javac.target" value="1.6"/>

<property name="fedoragsearch.version" value="2.8.1"/>
<property name="fedoragsearch.version" value="2.9.0"/>
<property name="fedora.version" value="3.7.1"/>
<property name="solr.version" value="4.6.1"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ private void checkStylesheet(String configPath) {
transformer = tfactory.newTransformer(xslt);
} catch (TransformerConfigurationException e) {
errors.append("\n*** Stylesheet "+configPath+" error:\n"+e.toString());
return;
}
String testSource = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
"<emptyTestDocumentRoot/>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import java.net.URL;

import java.util.Date;
import java.util.Map;
import java.util.Properties;

import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
Expand Down Expand Up @@ -52,6 +54,7 @@ public class GTransformer {

private static final Logger logger =
Logger.getLogger(GTransformer.class);

int debuglength = 500;

public GTransformer() {
Expand Down Expand Up @@ -175,6 +178,26 @@ public StringBuffer transform(String xsltName, Source sourceStream, URIResolver
transformer.setParameter((String)params[i], value);
}
transformer.setParameter("DATETIME", new Date());

final Properties customProperties = new Properties();
try {
final String path = String.format("/%s/%s", (new File(xsltName)).getParent(), "custom_parameters.properties");
final InputStream customParameterStream = this.getClass().getResourceAsStream(path);
if (customParameterStream == null) {
logger.debug(String.format("The %s file does not exist.", path));
}
else {
customProperties.load(customParameterStream);
for (final Map.Entry<Object, Object> i: customProperties.entrySet()) {
final String name = (String) i.getKey();
transformer.setParameter(name, i.getValue());
}
}
}
catch (IOException no_load) {
logger.debug("Failed to load custom_parameters.properties... It may either not exist or be unreadable.", no_load);
}

StreamResult destStream = new StreamResult(new StringWriter());
try {
transformer.transform(sourceStream, destStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.log4j.Appender;
import org.apache.log4j.Logger;

import dk.defxws.fedoragsearch.server.errors.ConfigException;
import dk.defxws.fedoragsearch.server.errors.GenericSearchException;

/**
Expand Down Expand Up @@ -110,12 +111,13 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
logger.debug("logger appender name="+appender.getName());
}
}
StringBuffer resultXml = new StringBuffer("<resultPage/>");
try {
config = Config.getCurrentConfig();
if (configName!=null && !"configure".equals(operation)) {
// mainly for test purposes
config = Config.getConfig(configName);
}
StringBuffer resultXml = new StringBuffer("<resultPage/>");
repositoryName = request.getParameter(PARAM_REPOSITORYNAME);
if (repositoryName==null) repositoryName="";
indexName = request.getParameter(PARAM_INDEXNAME);
Expand Down Expand Up @@ -197,9 +199,8 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
resultXml, params,
getServletContext().getRealPath("/WEB-INF/classes"));
}
// if (logger.isDebugEnabled())
// logger.debug("after "+restXslt+" result=\n"+resultXml);

if (logger.isInfoEnabled())
logger.info("request="+request.getQueryString()+" timeusedms="+timeusedms);
if (restXslt.indexOf(CONTENTTYPEHTML)>=0)
response.setContentType("text/html; charset=UTF-8");
else
Expand All @@ -209,8 +210,9 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
response.getOutputStream(), "UTF-8"));
out.print(resultXml);
out.close();
if (logger.isInfoEnabled())
logger.info("request="+request.getQueryString()+" timeusedms="+timeusedms);
} catch (ConfigException config_ex) {
response.sendError(500, config_ex.getMessage());
}
}

private String gfindObjects(HttpServletRequest request, HttpServletResponse response)
Expand Down