cancel
Showing results for 
Search instead for 
Did you mean: 

New aspect is found in javascript but not java

kbpair
Champ in-the-making
Champ in-the-making
I have created a new aspect (schemaValidation) and I can apply the aspect to content via the gui and javascript.

However if I try to check for this aspect in Java by building the QName I get an error saying:

Namespace prefix evg is not mapped to a namespace URI

Of course I use the namespace prefix in the javascript without any error. What am I missing?

here is my model file:

<?xml version="1.0" encoding="UTF-8"?>

<!– Custom Model –>

<!– Note: This model is pre-configured to load at startup of the Repository.  So, all custom –>
<!–       types and aspects added here will automatically be registered –>

<model name="evg:evergreenmodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">

   <!– Optional meta-data about the model –>  
   <description>Evergreen Model</description>
   <author></author>
   <version>1.0</version>

   <imports>
        <!– Import Alfresco Dictionary Definitions –>
      <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
      <!– Import Alfresco Content Domain Model Definitions –>
      <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
   </imports>

   <namespaces>
      <namespace uri="http://www.evergreeninvestments.com/vocab" prefix="evg"/>
   </namespaces>
  <types>
  </types>

    <aspects>
      <aspect name="evg:schemaValidation">
         <title>XML Schema Validation</title>
         <properties>
            <property name="evg:status">
               <type>d:int</type>
            </property>
            <property name="evg:message">
               <type>d:text</type>
            </property>
            <property name="evg:schema_node_ref">
               <type>d:noderef</type>
            </property>
            <property name="evg:schema_url">
               <type>d:text</type>
            </property>
         </properties>
      </aspect>
   </aspects>
  
</model>


and I use the following in my Java class

DynamicNamespacePrefixResolver nsRslvr = new DynamicNamespacePrefixResolver();
QName aspectQN = QName.createQName("evg","schemaValidation", nsRslvr);

I am hoping i just missed something simple. Any help is appreciated.
7 REPLIES 7

kbpair
Champ in-the-making
Champ in-the-making
I have also tried passing the namespace
QName aspectQN = QName.createQName("http://www.evergreeninvestments.com/vocab','schemaValidation");
and get the following error. I am really stumped and will take any suggestions.


10:08:10,563 ERROR [ui.common.Utils] Failed to run Actions due to error: Failed
to execute script 'workspace://SpacesStore/976566a7-c8cc-11db-900a-31d3e5b11671'
: Wrapped org.alfresco.service.cmr.dictionary.InvalidAspectException: The aspect
is invalid: {http://www.evergreeninvestments.com/vocab}schemaValidation (Alfres
coScript#13)
org.alfresco.service.cmr.repository.ScriptException: Failed to execute script 'w
orkspace://SpacesStore/976566a7-c8cc-11db-900a-31d3e5b11671': Wrapped org.alfres
co.service.cmr.dictionary.InvalidAspectException: The aspect is invalid: {http:/
/www.evergreeninvestments.com/vocab}schemaValidation (AlfrescoScript#13)
        at org.alfresco.repo.jscript.RhinoScriptService.executeScript(RhinoScrip
tService.java:168)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflecti
on(AopUtils.java:335)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJo
inpoint(ReflectiveMethodInvocation.java:181)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:148)
        at org.springframework.aop.support.DelegatingIntroductionInterceptor.inv
oke(DelegatingIntroductionInterceptor.java:116)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:170)
        at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterc
eptor.invoke(AlwaysProceedMethodInterceptor.java:40)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:170)
        at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethod
Interceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:170)
        at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.j
ava:204)
        at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInte
rceptor.java:69)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:170)
        at org.springframework.transaction.interceptor.TransactionInterceptor.in
voke(TransactionInterceptor.java:96)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:170)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynami
cAopProxy.java:176)
        at $Proxy55.executeScript(Unknown Source)
        at org.alfresco.repo.action.executer.ScriptActionExecuter.executeImpl(Sc
riptActionExecuter.java:148)
        at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(
ActionExecuterAbstractBase.java:120)
        at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(Acti
onServiceImpl.java:537)
        at org.alfresco.repo.action.ActionServiceImpl.executeActionImpl(ActionSe
rviceImpl.java:472)
        at org.alfresco.repo.action.ActionServiceImpl.executeAction(ActionServic
eImpl.java:399)
        at org.alfresco.repo.action.ActionServiceImpl.executeAction(ActionServic
eImpl.java:387)
        at org.alfresco.repo.action.ActionServiceImpl.executeAction(ActionServic
eImpl.java:545)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflecti
on(AopUtils.java:335)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJo
inpoint(ReflectiveMethodInvocation.java:181)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:148)
        at org.springframework.aop.support.DelegatingIntroductionInterceptor.inv
oke(DelegatingIntroductionInterceptor.java:116)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:170)
        at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterc
eptor.invoke(AlwaysProceedMethodInterceptor.java:40)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:170)
        at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethod
Interceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:170)
        at org.alfresco.repo.audit.AuditComponentImpl.auditImpl(AuditComponentIm
pl.java:219)
        at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.j
ava:165)
        at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInte
rceptor.java:69)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:170)
        at org.springframework.transaction.interceptor.TransactionInterceptor.in
voke(TransactionInterceptor.java:96)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:170)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynami
cAopProxy.java:176)
        at $Proxy16.executeAction(Unknown Source)
        at org.alfresco.web.bean.actions.RunActionWizard.finishImpl(RunActionWiz
ard.java:98)
        at org.alfresco.web.bean.dialog.BaseDialogBean.finish(BaseDialogBean.jav
a:115)
        at org.alfresco.web.bean.wizard.WizardManager.finish(WizardManager.java:
521)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java
:129)
        at org.apache.myfaces.application.ActionListenerImpl.processAction(Actio
nListenerImpl.java:63)
        at javax.faces.component.UICommand.broadcast(UICommand.java:106)
        at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:9
0)
        at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1
64)
        at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(Lifecycl
eImpl.java:316)
        at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java
:86)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:105)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:173)
        at org.alfresco.web.app.servlet.AuthenticationFilter.doFilter(Authentica
tionFilter.java:81)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:178)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:869)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.p
rocessConnection(Http11BaseProtocol.java:664)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
int.java:527)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFol
lowerWorkerThread.java:80)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:684)
        at java.lang.Thread.run(Thread.java:595)
Caused by: org.alfresco.error.AlfrescoRuntimeException: Wrapped org.alfresco.ser
vice.cmr.dictionary.InvalidAspectException: The aspect is invalid: {http://www.e
vergreeninvestments.com/vocab}schemaValidation (AlfrescoScript#13)
        at org.alfresco.repo.jscript.RhinoScriptService.executeScriptImpl(RhinoS
criptService.java:311)
        at org.alfresco.repo.jscript.RhinoScriptService.executeScript(RhinoScrip
tService.java:164)
        … 80 more
Caused by: org.mozilla.javascript.WrappedException: Wrapped org.alfresco.service
.cmr.dictionary.InvalidAspectException: The aspect is invalid: {http://www.everg
reeninvestments.com/vocab}schemaValidation (AlfrescoScript#13)
        at org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:17
05)
        at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:157)
        at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:20
1)
        at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:308
2)
        at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2248)
        at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.j
ava:158)
        at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:3
37)
        at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:275
5)
        at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.j
ava:169)
        at org.mozilla.javascript.Context.evaluateReader(Context.java:1175)
        at org.alfresco.repo.jscript.RhinoScriptService.executeScriptImpl(RhinoS
criptService.java:299)
        … 81 more
Caused by: org.alfresco.service.cmr.dictionary.InvalidAspectException: The aspec
t is invalid: {http://www.evergreeninvestments.com/vocab}schemaValidation
        at org.alfresco.repo.node.db.DbNodeServiceImpl.addAspect(DbNodeServiceIm
pl.java:549)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.alfresco.repo.service.StoreRedirectorProxyFactory$RedirectorInvoc
ationHandler.invoke(StoreRedirectorProxyFactory.java:221)
        at $Proxy2.addAspect(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflecti
on(AopUtils.java:335)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJo
inpoint(ReflectiveMethodInvocation.java:181)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:148)
        at org.alfresco.repo.node.MLPropertyInterceptor.invoke(MLPropertyInterce
ptor.java:227)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:170)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynami
cAopProxy.java:176)
        at $Proxy3.addAspect(Unknown Source)
        at com.evergreeninvestments.alfresco.action.XmlValidator.executeImpl(Xml
Validator.java:112)
        at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(
ActionExecuterAbstractBase.java:120)
        at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(Acti
onServiceImpl.java:537)
        at org.alfresco.repo.action.ActionServiceImpl.executeActionImpl(ActionSe
rviceImpl.java:472)
        at org.alfresco.repo.action.ActionServiceImpl.executeAction(ActionServic
eImpl.java:399)
        at org.alfresco.repo.action.ActionServiceImpl.executeAction(ActionServic
eImpl.java:387)
        at org.alfresco.repo.action.ActionServiceImpl.executeAction(ActionServic
eImpl.java:545)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflecti
on(AopUtils.java:335)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJo
inpoint(ReflectiveMethodInvocation.java:181)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:148)
        at org.springframework.aop.support.DelegatingIntroductionInterceptor.inv
oke(DelegatingIntroductionInterceptor.java:116)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:170)
        at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterc
eptor.invoke(AlwaysProceedMethodInterceptor.java:40)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:170)
        at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethod
Interceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:170)
        at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.j
ava:204)
        at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInte
rceptor.java:69)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:170)
        at org.springframework.transaction.interceptor.TransactionInterceptor.in
voke(TransactionInterceptor.java:96)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:170)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynami
cAopProxy.java:176)
        at $Proxy16.executeAction(Unknown Source)
        at org.alfresco.repo.jscript.ScriptAction.execute(ScriptAction.java:127)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:142)
        … 90 more

kevinr
Star Contributor
Star Contributor
and I use the following in my Java class

DynamicNamespacePrefixResolver nsRslvr = new DynamicNamespacePrefixResolver();
QName aspectQN = QName.createQName("evg","schemaValidation", nsRslvr);

You should be using the NamespaceService itself - the DynamicNamespacePrefixResolver will not resolve to your model unless you construct it using the NamespaceService anyway.

Use Spring to bind in the NamespaceService along with your other services, then you can do this:

QName aspectQN = QName.createQName("evg","schemaValidation", this.namespaceService);

Thanks,

Kevin

kbpair
Champ in-the-making
Champ in-the-making
Thanks for the note on how to properly search for namespaces, unfortunately after the changes I still have issues. The prefix 'evg' is resolved to the proper namespace, as it was being done in my previous post, but the aspect is invalid.

Of course in the javascript code I check to see if the document has this aspect and the code works without any errors.

I am getting really frustrated - I am evaluating Alfresco for my current project and have to present my findings in a day and a half. So far the 'simple' assignment of validating the content against a schema is causing all kinds of issues.

So if anybody can help with this I would really appreciate it.

davidc
Star Contributor
Star Contributor
Could you restate your issue please?

You say the javascript works, but the stack trace is from executing a script.  You also say that the namespace prefix is not mapped correctly in java, but then say it is.

Please post your line of java code where the exception is raised.

kbpair
Champ in-the-making
Champ in-the-making
Sorry for being unclear. In my effort to get this working I tried to use the DynamicNamespaceResolver which led to the namespace mapping issue. The real issue is that my custom aspect is 'invalid' when accessed via the java code.

The java code is called from a script which may also be leading to some confusion.

After creating my custom aspect I run this javascript to set a property:

var metwest_schema_nd = 'workspace://SpacesStore/90329581-c8c8-11db-900a-31d3e5b11671';
// example of hasAspect() API functions
if (document.hasAspect("evg:schemaValidation"))
{
document.properties["evg:schema_node_ref"] = metwest_schema_nd;
document.save();
}

This script runs without any issues - the document has the aspect and the property is set.

Then I call the next script (which in turn calls my java class)

//create Action
var act = actions.create("xmlvalidator");
act.execute(document);

As you can see there is really nothing in this script and the resulting error is actually from the java class.

Here is the Java:

package com.evergreeninvestments.alfresco.action;

import java.io.IOException;
import java.util.List;

import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;

import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;


public class XmlValidator extends ActionExecuterAbstractBase {

  
    /** The name of the action */
    public static final String NAME = "xml-validator-action"; 
    private static String nspre = "evg";
   
   
    private NodeService nodeService;
    private ContentService contentService;
    private NamespaceService namespaceService;

    public void setNodeService(NodeService nodeService)
    {
       this.nodeService = nodeService;
    }

    public void setContentService(ContentService contentService)
    {
       this.contentService = contentService;
    }

    public void setNamespaceService(NamespaceService namespaceService)
    {
       this.namespaceService = namespaceService;
    }

   @Override
   protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
      int currStatus = 1;
      String currMsg = "";
      NodeRef schemaNdRef = null;
      ContentData content = null;

       QName aspectQN = QName.createQName(nspre,"schemaValidation", namespaceService);
       QName ndrefQN = QName.createQName(nspre,"schema_node_ref", namespaceService);
       QName statusQN = QName.createQName(nspre,"status", namespaceService);
       QName msgQN = QName.createQName(nspre,"message", namespaceService);
      
      if (nodeService.exists(actionedUponNodeRef) == true)
        {
            if (nodeService.hasAspect(actionedUponNodeRef, aspectQN)) {
               //get schema node ref
               schemaNdRef = (NodeRef)nodeService.getProperty(actionedUponNodeRef, ndrefQN);
            } else {
              //add aspect
               nodeService.addAspect(actionedUponNodeRef, aspectQN, null);
            }
            //get xml content
            content = (ContentData)nodeService.getProperty(actionedUponNodeRef, ContentModel.PROP_CONTENT);
          if (content.getSize() < 1) {
             //content is empty
             currStatus = 1;
             currMsg = "XML Document Not Found";
          }
          else
          {
             ContentReader actRdr = contentService.getReader(actionedUponNodeRef, ContentModel.PROP_CONTENT);
            try
            {
                
               // parse an XML document into a DOM tree
                DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                Document document = null;
               try {
                  document = parser.parse(actRdr.getContentInputStream());
                  //well-formed, get schema for validation
                     ContentReader schemaRdr = contentService.getReader(schemaNdRef, ContentModel.PROP_CONTENT);
                     if (schemaRdr.getSize() > 0) {
                       
                       // create a SchemaFactory capable of understanding WXS schemas
                      SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            
                      // load a WXS schema, represented by a Schema instance
                      Schema schema = factory.newSchema(new StreamSource(schemaRdr.getContentInputStream()));
            
                      // create a Validator instance, which can be used to validate an instance document
                      Validator validator = schema.newValidator();
            
                      // validate the DOM tree
                      try {
                          validator.validate(new DOMSource(document));
                         currStatus = 4;
                         currMsg = "XML Document is valid and well-formed";
                      } catch (SAXException e) {
                          // instance document is invalid!
                         currStatus = 3;
                         currMsg = "Document is not valid.: " + e.toString();
                      }
                    } 
               } catch (SAXException e1) {
                  // Document not well formed
                   currStatus = 2;
                   currMsg = "XML Document Not Well-Formed.: " + e1.toString();
               }
            }catch(ParserConfigurationException pce) {
                currStatus = 1;
                currMsg = "ParserConfigurationException: " + pce.toString();
               pce.printStackTrace();
            }catch(IOException io) {
                currStatus = 1;
                currMsg = "IOException: " + io.toString();
               io.printStackTrace();
            }
          }
          nodeService.setProperty(actionedUponNodeRef, statusQN, currStatus);
          nodeService.setProperty(actionedUponNodeRef, msgQN, currMsg);
        }
   }

   @Override
   protected void addParameterDefinitions(List<ParameterDefinition> paramList) {
        // Specify the parameters
//        paramList.add(new ParameterDefinitionImpl(PARAM_SCHEMA_URL, DataTypeDefinition.TEXT, true, getParamDisplayLabel(PARAM_SCHEMA_URL)));

   }

}


Why is the aspect valid in javascript but not in java?

davidc
Star Contributor
Star Contributor
That is odd.

Can you:

1) enable log4j.logger.org.alfresco.repo.dictionary.DictionaryDAO=info in log4j.properties (this will give some info on which namespaces and models are loaded on startup of the repository)

2) provide the spring configuration for your action bean

3) provide the value of aspectQN.toString()

I'm assuming the exception comes

if (nodeService.hasAspect(actionedUponNodeRef, aspectQN)) {

kbpair
Champ in-the-making
Champ in-the-making
It appears to be working now.

The namespace did not match the namespace being loaded.

The last QName code I was using was incorrect, as it was setting the prefix as the URI. Therefore it did not find the aspect.

thanks for your help.