Skip to content

Commit

Permalink
-- formatXML() added to GUI Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
celsowm committed Jun 8, 2014
1 parent 3409212 commit 220dff7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
31 changes: 31 additions & 0 deletions controller/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@
import java.net.URI;
import java.util.*;
import java.util.Map.Entry;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.mindswap.pellet.exceptions.InconsistentOntologyException;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.util.*;
import org.semanticweb.owlapi.vocab.Namespaces;
import org.w3c.dom.Node;
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSSerializer;
import org.xml.sax.InputSource;

public class Util {

Expand Down Expand Up @@ -434,6 +440,31 @@ public static String getUserName() throws Exception {

}

public static String formatXML(String xml) {

try {
final InputSource src = new InputSource(new StringReader(xml));
final Node document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src).getDocumentElement();
final Boolean keepDeclaration = Boolean.valueOf(xml.startsWith("<?xml"));

System.setProperty(DOMImplementationRegistry.PROPERTY,"com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");


final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
final LSSerializer writer = impl.createLSSerializer();

writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); // Set this to true if the output needs to be beautified.
writer.getDomConfig().setParameter("xml-declaration", keepDeclaration); // Set this to true if the declaration is needed to be outputted.

return writer.writeToString(document);

} catch (Exception e) {
Util.getException(e);
return null;
}
}



}
12 changes: 6 additions & 6 deletions view/MainView.form
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<Property name="editable" type="boolean" value="false"/>
<Property name="text" type="java.lang.String" resourceKey="jDocumentTextField.text"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Cursor Default"/>
<Color id="Default Cursor"/>
</Property>
<Property name="name" type="java.lang.String" value="jDocumentTextField" noResource="true"/>
</Properties>
Expand All @@ -92,7 +92,7 @@
<Property name="editable" type="boolean" value="false"/>
<Property name="text" type="java.lang.String" resourceKey="jOntologyTextField.text"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Cursor Default"/>
<Color id="Default Cursor"/>
</Property>
<Property name="name" type="java.lang.String" value="jOntologyTextField" noResource="true"/>
</Properties>
Expand All @@ -102,7 +102,7 @@
<Property name="icon" type="javax.swing.Icon" resourceKey="jOntologyOpenBtn.icon"/>
<Property name="text" type="java.lang.String" resourceKey="jOntologyOpenBtn.text"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Cursor Default"/>
<Color id="Default Cursor"/>
</Property>
<Property name="name" type="java.lang.String" value="jOntologyOpenBtn" noResource="true"/>
</Properties>
Expand All @@ -115,7 +115,7 @@
<Property name="icon" type="javax.swing.Icon" resourceKey="jDocumentOpenBtn.icon"/>
<Property name="text" type="java.lang.String" resourceKey="jDocumentOpenBtn.text"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Cursor Default"/>
<Color id="Default Cursor"/>
</Property>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[159, 33]"/>
Expand Down Expand Up @@ -474,7 +474,7 @@
<Property name="icon" type="javax.swing.Icon" resourceKey="jRunButton.icon"/>
<Property name="text" type="java.lang.String" resourceKey="jRunButton.text"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Cursor Default"/>
<Color id="Default Cursor"/>
</Property>
<Property name="name" type="java.lang.String" value="jRunButton" noResource="true"/>
</Properties>
Expand Down Expand Up @@ -510,7 +510,7 @@
<Property name="text" type="java.lang.String" resourceKey="jRdfsLabelCheckBox.text"/>
<Property name="toolTipText" type="java.lang.String" resourceKey="jRdfsLabelCheckBox.toolTipText"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Cursor Default"/>
<Color id="Default Cursor"/>
</Property>
<Property name="focusable" type="boolean" value="false"/>
<Property name="horizontalAlignment" type="int" value="2"/>
Expand Down
8 changes: 7 additions & 1 deletion view/MainView.java
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,13 @@ private void jRunButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI
AutoAnnotator autoAnnotator = new AutoAnnotator(documentText, ontology, reasoning, label, exhaustive, reasoner);
String rdfa = Manager.getDocumentoAnotado(autoAnnotator);

jResultHtml.setText(rdfa);
String formattedRdfa = Util.formatXML(rdfa);
if(formattedRdfa != null){
jResultHtml.setText(formattedRdfa);
}else{
jResultHtml.setText(rdfa);
}

File temp = Util.textToTempFile(rdfa);
System.out.println(temp.getAbsolutePath());
jTableResultados.setModel(Extractor.parseRDFaToTableModel(temp.getAbsolutePath()));
Expand Down

0 comments on commit 220dff7

Please sign in to comment.