-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3697 from inception-project/feature/3602-Enable-S…
…pring-MVC-CSP #3602 - Enable Spring MVC CSP
- Loading branch information
Showing
10 changed files
with
277 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...main/java/de/tudarmstadt/ukp/inception/pdfeditor2/resources/PdfJsJavaScriptReference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Licensed to the Technische Universität Darmstadt under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The Technische Universität Darmstadt | ||
* licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. | ||
* | ||
* 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, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package de.tudarmstadt.ukp.inception.pdfeditor2.resources; | ||
|
||
import org.apache.wicket.request.resource.JavaScriptResourceReference; | ||
|
||
public class PdfJsJavaScriptReference | ||
extends JavaScriptResourceReference | ||
{ | ||
private static final long serialVersionUID = 1L; | ||
|
||
private static final PdfJsJavaScriptReference INSTANCE = new PdfJsJavaScriptReference(); | ||
|
||
/** | ||
* Gets the instance of the resource reference | ||
* | ||
* @return the single instance of the resource reference | ||
*/ | ||
public static PdfJsJavaScriptReference get() | ||
{ | ||
return INSTANCE; | ||
} | ||
|
||
/** | ||
* Private constructor | ||
*/ | ||
private PdfJsJavaScriptReference() | ||
{ | ||
super(PdfJsJavaScriptReference.class, "pdf.min.js"); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...n/java/de/tudarmstadt/ukp/inception/pdfeditor2/resources/PdfJsViewerJavaCssReference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Licensed to the Technische Universität Darmstadt under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The Technische Universität Darmstadt | ||
* licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. | ||
* | ||
* 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, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package de.tudarmstadt.ukp.inception.pdfeditor2.resources; | ||
|
||
import org.apache.wicket.request.resource.CssResourceReference; | ||
|
||
public class PdfJsViewerJavaCssReference | ||
extends CssResourceReference | ||
{ | ||
private static final long serialVersionUID = 1L; | ||
|
||
private static final PdfJsViewerJavaCssReference INSTANCE = new PdfJsViewerJavaCssReference(); | ||
|
||
/** | ||
* Gets the instance of the resource reference | ||
* | ||
* @return the single instance of the resource reference | ||
*/ | ||
public static PdfJsViewerJavaCssReference get() | ||
{ | ||
return INSTANCE; | ||
} | ||
|
||
/** | ||
* Private constructor | ||
*/ | ||
private PdfJsViewerJavaCssReference() | ||
{ | ||
super(PdfJsViewerJavaCssReference.class, "viewer.css"); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...ava/de/tudarmstadt/ukp/inception/pdfeditor2/resources/PdfJsViewerJavaScriptReference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Licensed to the Technische Universität Darmstadt under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The Technische Universität Darmstadt | ||
* licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. | ||
* | ||
* 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, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package de.tudarmstadt.ukp.inception.pdfeditor2.resources; | ||
|
||
import static java.util.Arrays.asList; | ||
|
||
import java.util.List; | ||
|
||
import org.apache.wicket.markup.head.CssContentHeaderItem; | ||
import org.apache.wicket.markup.head.HeaderItem; | ||
import org.apache.wicket.markup.head.JavaScriptHeaderItem; | ||
import org.apache.wicket.request.resource.JavaScriptResourceReference; | ||
|
||
public class PdfJsViewerJavaScriptReference | ||
extends JavaScriptResourceReference | ||
{ | ||
private static final long serialVersionUID = 1L; | ||
|
||
private static final PdfJsViewerJavaScriptReference INSTANCE = new PdfJsViewerJavaScriptReference(); | ||
|
||
/** | ||
* Gets the instance of the resource reference | ||
* | ||
* @return the single instance of the resource reference | ||
*/ | ||
public static PdfJsViewerJavaScriptReference get() | ||
{ | ||
return INSTANCE; | ||
} | ||
|
||
@Override | ||
public List<HeaderItem> getDependencies() | ||
{ | ||
return asList( // | ||
CssContentHeaderItem.forReference(PdfJsViewerJavaCssReference.get()), | ||
JavaScriptHeaderItem.forReference(PdfJsJavaScriptReference.get())); | ||
} | ||
|
||
/** | ||
* Private constructor | ||
*/ | ||
private PdfJsViewerJavaScriptReference() | ||
{ | ||
super(PdfJsViewerJavaScriptReference.class, "viewer.js"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...or2/src/main/java/de/tudarmstadt/ukp/inception/pdfeditor2/view/pdfjs/PdfJsViewerPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Licensed to the Technische Universität Darmstadt under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The Technische Universität Darmstadt | ||
* licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. | ||
* | ||
* 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, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package de.tudarmstadt.ukp.inception.pdfeditor2.view.pdfjs; | ||
|
||
import static de.tudarmstadt.ukp.inception.pdfeditor2.config.PdfAnnotationEditor2WebMvcConfiguration.BASE_URL; | ||
import static org.apache.wicket.core.util.string.CssUtils.ATTR_LINK_HREF; | ||
import static org.apache.wicket.core.util.string.CssUtils.ATTR_LINK_REL; | ||
import static org.apache.wicket.core.util.string.CssUtils.ATTR_TYPE; | ||
|
||
import javax.servlet.ServletContext; | ||
|
||
import org.apache.wicket.MarkupContainer; | ||
import org.apache.wicket.markup.IMarkupCacheKeyProvider; | ||
import org.apache.wicket.markup.IMarkupResourceStreamProvider; | ||
import org.apache.wicket.markup.head.IHeaderResponse; | ||
import org.apache.wicket.markup.head.JavaScriptHeaderItem; | ||
import org.apache.wicket.markup.head.StringHeaderItem; | ||
import org.apache.wicket.markup.html.WebPage; | ||
import org.apache.wicket.request.UrlRenderer; | ||
import org.apache.wicket.request.cycle.RequestCycle; | ||
import org.apache.wicket.spring.injection.annot.SpringBean; | ||
import org.apache.wicket.util.resource.IResourceStream; | ||
import org.apache.wicket.util.value.AttributeMap; | ||
import org.wicketstuff.annotation.mount.MountPath; | ||
|
||
import de.tudarmstadt.ukp.clarin.webanno.support.wicket.InputStreamResourceStream; | ||
import de.tudarmstadt.ukp.inception.pdfeditor2.config.PdfAnnotationEditor2WebMvcConfiguration; | ||
import de.tudarmstadt.ukp.inception.pdfeditor2.resources.PdfJsViewerJavaScriptReference; | ||
|
||
@MountPath(PdfAnnotationEditor2WebMvcConfiguration.BASE_URL + "/viewer.html") | ||
public class PdfJsViewerPage | ||
extends WebPage | ||
implements IMarkupResourceStreamProvider, IMarkupCacheKeyProvider | ||
{ | ||
private static final long serialVersionUID = -6785521330117759815L; | ||
|
||
private @SpringBean ServletContext servletContext; | ||
|
||
@Override | ||
public void renderHead(IHeaderResponse aResponse) | ||
{ | ||
renderLocaleReference(aResponse); | ||
|
||
aResponse.render(JavaScriptHeaderItem.forReference(PdfJsViewerJavaScriptReference.get())); | ||
var script = String.join("\n", // | ||
"window.addEventListener('DOMContentLoaded', function() {", // | ||
" PDFViewerApplicationOptions.set('defaultUrl', null);", // | ||
" PDFViewerApplicationOptions.set('disablePreferences', true);", // | ||
" PDFViewerApplicationOptions.set('workerSrc', 'pdf.worker.min.js');", // | ||
" PDFViewerApplicationOptions.set('enableScripting', false);", // | ||
" PDFViewerApplicationOptions.set('viewOnLoad', 1);", // | ||
// Because when when we jump to a location in a different document it sucks when | ||
// the sidebar automatically opens and causes a re-scaling which leads to a wrong | ||
// scroll position! | ||
" PDFViewerApplicationOptions.set('sidebarViewOnLoad', 0);", // | ||
"});"); | ||
aResponse.render(JavaScriptHeaderItem.forScript(script, "initialization")); | ||
} | ||
|
||
private void renderLocaleReference(IHeaderResponse aResponse) | ||
{ | ||
UrlRenderer urlRenderer = RequestCycle.get().getUrlRenderer(); | ||
String localeUrl = urlRenderer | ||
.renderContextRelativeUrl(BASE_URL + "/locale/locale.properties"); | ||
|
||
AttributeMap attributes = new AttributeMap(); | ||
attributes.putAttribute(ATTR_LINK_REL, "resource"); | ||
attributes.putAttribute(ATTR_TYPE, "application/l10n"); | ||
attributes.putAttribute(ATTR_LINK_HREF, localeUrl); | ||
aResponse.render(new StringHeaderItem("<link" + attributes.toCharSequence() + " />")); | ||
} | ||
|
||
@Override | ||
public String getCacheKey(MarkupContainer container, Class<?> containerClass) | ||
{ | ||
return getClass().getName(); | ||
} | ||
|
||
@Override | ||
public IResourceStream getMarkupResourceStream(MarkupContainer aContainer, | ||
Class<?> aContainerClass) | ||
{ | ||
return new InputStreamResourceStream(getClass().getResourceAsStream( | ||
"/de/tudarmstadt/ukp/inception/pdfeditor2/resources/viewer.html")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters