2424import org .w3c .dom .NodeList ;
2525
2626import jakarta .servlet .ServletContext ;
27+ import jakarta .ws .rs .InternalServerErrorException ;
2728import javax .xml .parsers .DocumentBuilder ;
2829import javax .xml .parsers .DocumentBuilderFactory ;
2930import javax .xml .transform .OutputKeys ;
3738import java .nio .file .Paths ;
3839import java .util .ArrayList ;
3940import java .util .List ;
41+ import javax .xml .parsers .ParserConfigurationException ;
42+ import javax .xml .transform .TransformerException ;
43+ import org .w3c .dom .DOMException ;
44+ import org .xml .sax .SAXException ;
4045
4146/**
4247 * Updates master XSLT stylesheets with package import chains.
@@ -49,7 +54,6 @@ public class XsltMasterUpdater
4954 private static final Logger log = LoggerFactory .getLogger (XsltMasterUpdater .class );
5055
5156 private static final String XSL_NS = "http://www.w3.org/1999/XSL/Transform" ;
52- private static final String XS_NS = "http://www.w3.org/2001/XMLSchema" ;
5357
5458 private final ServletContext servletContext ;
5559
@@ -64,28 +68,25 @@ public XsltMasterUpdater(ServletContext servletContext)
6468 }
6569
6670 /**
67- * Regenerates the master stylesheet for an application hostname .
68- * The master stylesheet must exist at /static/<hostname> /layout.xsl.
71+ * Regenerates the master stylesheet for the application.
72+ * The master stylesheet must exist at /static/xsl /layout.xsl.
6973 * This method loads it and adds/updates xsl:import elements for packages.
7074 *
71- * @param hostname the application hostname (e.g., "localhost")
7275 * @param packagePaths list of package paths to import (e.g., ["com/linkeddatahub/packages/skos"])
7376 * @throws IOException if file operations fail
7477 */
75- public void regenerateMasterStylesheet (String hostname , List <String > packagePaths ) throws IOException
78+ public void regenerateMasterStylesheet (List <String > packagePaths ) throws IOException
7679 {
77- if (hostname == null ) throw new IllegalArgumentException ("Hostname cannot be null" );
78-
7980 try
8081 {
8182 Path staticDir = getStaticPath ();
82- Path hostnameDir = staticDir .resolve (hostname );
83- Path masterFile = hostnameDir .resolve ("layout.xsl" );
83+ Path xslDir = staticDir .resolve ("xsl" );
84+ Path masterFile = xslDir .resolve ("layout.xsl" );
8485
8586 // Master stylesheet must exist
8687 if (!Files .exists (masterFile ))
8788 {
88- throw new jakarta . ws . rs . InternalServerErrorException ("Master stylesheet does not exist: " + masterFile );
89+ throw new InternalServerErrorException ("Master stylesheet does not exist: " + masterFile );
8990 }
9091
9192 // Load existing master stylesheet
@@ -136,7 +137,7 @@ public void regenerateMasterStylesheet(String hostname, List<String> packagePath
136137 }
137138
138139 // Write to file
139- Files .createDirectories (hostnameDir );
140+ Files .createDirectories (xslDir );
140141 TransformerFactory transformerFactory = TransformerFactory .newInstance ();
141142 Transformer transformer = transformerFactory .newTransformer ();
142143 transformer .setOutputProperty (OutputKeys .INDENT , "yes" );
@@ -147,9 +148,9 @@ public void regenerateMasterStylesheet(String hostname, List<String> packagePath
147148 StreamResult result = new StreamResult (masterFile .toFile ());
148149 transformer .transform (source , result );
149150
150- if (log .isDebugEnabled ()) log .debug ("Regenerated master stylesheet for hostname '{}' at: {}" , hostname , masterFile );
151+ if (log .isDebugEnabled ()) log .debug ("Regenerated master stylesheet at: {}" , masterFile );
151152 }
152- catch (Exception e )
153+ catch (InternalServerErrorException | IOException | IllegalArgumentException | IllegalStateException | ParserConfigurationException | TransformerException | DOMException | SAXException e )
153154 {
154155 throw new IOException ("Failed to regenerate master stylesheet" , e );
155156 }
@@ -174,7 +175,7 @@ private Element findSystemImport(Element stylesheet)
174175 }
175176
176177 /**
177- * Removes all xsl:import elements for packages.
178+ * Removes all <samp> xsl:import</samp> elements for packages.
178179 * Identifies package imports by checking if they have a preceding comment containing "Package:".
179180 */
180181 private void removePackageImports (Element stylesheet )
0 commit comments