Skip to content

Commit

Permalink
Code review.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexJitianu committed Dec 18, 2017
1 parent 124409b commit 7911a91
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 103 deletions.
5 changes: 5 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,10 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
3 changes: 2 additions & 1 deletion frameworks/xspec/oxygen-results-view/build_report.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@


<echo>Apply driver to execute the templates: ${xspec.template.name.entrypoint}</echo>
<makeurl file="${xspec.xsl}" property="xspec.xsl.uri"/>

<java classname="net.sf.saxon.Transform"
fork="true">
Expand All @@ -170,7 +171,7 @@
<arg value="-xsl:${compile.xspec.xsl.driver}" />

<arg value="xspec.template.name.entrypoint=${xspec.template.name.entrypoint}" />
<arg value="compiled-stylesheet-uri=file:/${xspec.xsl}" />
<arg value="compiled-stylesheet-uri=${xspec.xsl.uri}" />

<arg value="-config:${xspec.saxon.config}" />
</java>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.oxygenxml.xspec;

/**
* Operation canceled.
*
*/
public class OperationCanceledException extends Exception {

}
3 changes: 1 addition & 2 deletions src/main/java/com/oxygenxml/xspec/XSpecResultsView.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import org.apache.log4j.Logger;

import com.oxygenxml.xspec.XSpecUtil.OperationCanceledException;
import com.oxygenxml.xspec.jfx.BrowserInteractor;
import com.oxygenxml.xspec.jfx.SwingBrowserPanel;
import com.oxygenxml.xspec.jfx.bridge.Bridge;
Expand Down Expand Up @@ -218,7 +217,7 @@ public void transformationFinished(boolean success) {
enableButtons(true);
}
} catch (Exception e) {
e.printStackTrace();
logger.error(e, e);
enableButtons(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import javax.swing.ImageIcon;
import javax.swing.JComponent;

import com.oxygenxml.xspec.XSpecUtil.OperationCanceledException;

import ro.sync.exml.plugin.workspace.WorkspaceAccessPluginExtension;
import ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace;
import ro.sync.exml.workspace.api.standalone.ToolbarComponentsCustomizer;
Expand Down
12 changes: 2 additions & 10 deletions src/main/java/com/oxygenxml/xspec/XSpecUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void run() {
counter ++;
}
} catch (InterruptedException e) {
e.printStackTrace();
logger.error(e, e);
}

if (documentTypeInformation != null) {
Expand Down Expand Up @@ -170,7 +170,7 @@ public void transformationFinished(boolean success) {
try {
resultsPresenter.load(editorLocation, new URL(toOpen));
} catch (MalformedURLException e) {
e.printStackTrace();
logger.error(e, e);
}
} else {
resultsPresenter.loadContent("");
Expand Down Expand Up @@ -247,14 +247,6 @@ private static WSEditor getXSpecEditor(
return currentEditorAccess;
}

/**
* Operation canceled.
*
*/
public static class OperationCanceledException extends Exception {

}

/**
* Generates an unique ID based on the given seed.
*
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/com/oxygenxml/xspec/jfx/bridge/Bridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@

import org.apache.log4j.Logger;

import com.oxygenxml.xspec.OperationCanceledException;
import com.oxygenxml.xspec.XSpecResultPresenter;
import com.oxygenxml.xspec.XSpecUtil;
import com.oxygenxml.xspec.XSpecUtil.OperationCanceledException;
import com.oxygenxml.xspec.XSpecVariablesResolver;
import com.oxygenxml.xspec.protocol.DiffFragmentRepository;

import javafx.scene.web.WebEngine;
import netscape.javascript.JSObject;
import ro.sync.exml.workspace.api.PluginWorkspace;
import ro.sync.exml.workspace.api.PluginWorkspaceProvider;
import ro.sync.exml.workspace.api.editor.WSEditor;
import ro.sync.exml.workspace.api.editor.page.WSEditorPage;
import ro.sync.exml.workspace.api.editor.page.text.xml.WSXMLTextEditorPage;
import ro.sync.exml.workspace.api.editor.page.text.xml.WSXMLTextNodeRange;
import ro.sync.exml.workspace.api.editor.page.text.xml.XPathException;
import ro.sync.exml.workspace.api.editor.transformation.TransformationFeedback;
import ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace;
import ro.sync.exml.workspace.api.util.XMLUtilAccess;

/**
* A bridge between JavaScript and Java. JavaScript code will be able to invoke
Expand Down Expand Up @@ -161,9 +163,9 @@ private void showTestAWT(String testName, String scenarioName, String scenarioLo
logger.warn("Unable to identify test");
}
} catch (XPathException e) {
e.printStackTrace();
logger.error(e, e);
} catch (BadLocationException e) {
e.printStackTrace();
logger.error(e, e);
}

}
Expand Down Expand Up @@ -238,11 +240,15 @@ public void showDiff(String left, String right) {
try {
DiffFragmentRepository instance = DiffFragmentRepository.getInstance();


XMLUtilAccess xmlUtilAccess = PluginWorkspaceProvider.getPluginWorkspace().getXMLUtilAccess();
String lu = xmlUtilAccess.unescapeAttributeValue(left);
String lr = xmlUtilAccess.unescapeAttributeValue(right);
final URL url1 = instance.cache(
left,
lu,
"RESULT");
final URL url2 = instance.cache(
right,
lr,
"EXPECTED");

if (logger.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import ro.sync.exml.editor.ContentTypes;
import ro.sync.exml.workspace.api.PluginWorkspaceProvider;
import ro.sync.util.URLUtil;

/**
* A repository for the XML fragments that can be accessed through the DIFF protocol.
Expand All @@ -24,6 +25,11 @@ public class DiffFragmentRepository {
*/
private static final Logger logger = Logger.getLogger(DiffFragmentRepository.class.getName());

/**
* Protocol name.
*/
public static final String DIFF_PROTOCOL = "diff";

/**
* Singleton instance.
*/
Expand Down Expand Up @@ -118,17 +124,6 @@ private String getContentType(String fragment) {
return isXML ? ContentTypes.XML_CONTENT_TYPE : ContentTypes.PLAIN_TEXT_CONTENT_TYPE;
}

/**
* Gets the fragment associated with the given key.
*
* @param key The key that identifies a fragment.
*
* @return The fragment or null if the key is not mapped to any fragment.
*/
public DiffFragment get(int key) {
return cache.get(key);
}

/**
* Checks of the fragment is present in the cache.
*
Expand Down Expand Up @@ -160,14 +155,62 @@ public void dispose() {
public URL cache(String fragment, String host) throws MalformedURLException {
int key = fragment.hashCode();
if (!contains(key)) {
// fragment = fragment.replace("&lt;", "<");
fragment = PluginWorkspaceProvider.getPluginWorkspace().getXMLUtilAccess().unescapeAttributeValue(fragment);

logger.info("Fragment " + fragment);

put(key, fragment);
}

return DiffURLStreamHandler.build(key, host);
return build(DIFF_PROTOCOL, key, host);
}

/**
* Gets the fragment identified by this URL.
*
* @param u The URL.
*
* @return The fragment or <code>null</code>.
*/
public String getFragment(URL u) {
String fragment = null;

String fileName = URLUtil.extractFileName(u);
String extension = URLUtil.getExtension(fileName);

String idAsString = fileName.substring(0, fileName.length() - extension.length() - 1);

try {
int key = Integer.parseInt(idAsString);

DiffFragment diffFragment = cache.get(key);
if (diffFragment != null) {
fragment = diffFragment.getContent();
}

} catch (Throwable t) {
logger.error(t, t);
}

return fragment;
}

/**
* Builds an URL to identify a fragment with teh given key.
*
* @param key The key.
* @param host Something to put as host name.
*
* @return The URL form.
*
* @throws MalformedURLException Problems building the URL.
*/
public URL build(String protocol, int key, String host) throws MalformedURLException {
DiffFragment diffFragment = cache.get(key);
StringBuilder b = new StringBuilder(protocol);
b.append(":/").append(host).append("/").append(key).append(".");
if (diffFragment.getContentType().equals(ContentTypes.XML_CONTENT_TYPE)) {
b.append("xml");
} else {
b.append("txt");
}
return new URL(b.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,84 +3,22 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;

import org.apache.log4j.Logger;

import ro.sync.exml.editor.ContentTypes;
import ro.sync.util.URLUtil;

public class DiffURLStreamHandler extends URLStreamHandler {
/**
* Logger for logging.
*/
private static final Logger logger = Logger.getLogger(DiffURLStreamHandler.class.getName());

/**
* Protocol name.
*/
public static final String DIFF_PROTOCOL = "diff";
public static final String DIFF_PROTOCOL = DiffFragmentRepository.DIFF_PROTOCOL;

@Override
protected URLConnection openConnection(URL u) throws IOException {
return new DiffURLConnection(u);
}

/**
* Builds an URL to identify the given key.
*
* @param key The key.
* @param host Something to put as host name.
*
* @return The URL form.
*
* @throws MalformedURLException Problems building the URL.
*/
public static URL build(int key, String host) throws MalformedURLException {
DiffFragment diffFragment = DiffFragmentRepository.getInstance().get(key);
StringBuilder b = new StringBuilder(DIFF_PROTOCOL);
b.append(":/").append(host).append("/").append(key).append(".");
if (diffFragment.getContentType().equals(ContentTypes.XML_CONTENT_TYPE)) {
b.append("xml");
} else {
b.append("txt");
}
return new URL(b.toString());
}

/**
* Gets the fragment identified by this URL.
*
* @param u The URL.
*
* @return The fragment or <code>null</code>.
*/
private static String getFragment(URL u) {
String fragment = null;

String fileName = URLUtil.extractFileName(u);
String extension = URLUtil.getExtension(fileName);

String idAsString = fileName.substring(0, fileName.length() - extension.length() - 1);

try {
int key = Integer.parseInt(idAsString);

DiffFragment diffFragment = DiffFragmentRepository.getInstance().get(key);
if (diffFragment != null) {
fragment = diffFragment.getContent();
}

} catch (Throwable t) {
logger.error(t, t);
}

return fragment;
}

/**
* Connection for a DIFF fragment identifying URL.
*
Expand All @@ -101,7 +39,7 @@ public void connect() throws IOException {}

@Override
public InputStream getInputStream() throws IOException {
String fragment = getFragment(url);
String fragment = DiffFragmentRepository.getInstance().getFragment(url);
if (fragment == null) {
// Unable
throw new IOException("Unable to get the content");
Expand Down
Loading

0 comments on commit 7911a91

Please sign in to comment.