Okay, ich habe mir einige Stack-Overflow-Fragen und etliche Blogs angeschaut und kann immer noch keine Antwort darauf finden. Nein, es sieht nicht so aus, als ob es geschweifte Klammern, zusätzliche Strichpunkte oder andere Tippfehler gibt, die mir bekannt sind. Warum zeigt das 'sonst' einen Fehler? HierJava: Syntaxfehler auf Token "else"
// check if myid property is set and create it if not
String subtopicMyId = subtopicNode.hasProperty("myid") ? subtopicNode.getProperty("myid").getString() : "";
if (subtopicMyId.equals("")) {
// generate new myid and check it against the list of existing IDs until a unique one is generated
do {
// generate new myid
Object topicmyidobj = new Object();
subtopicMyId = topicmyidobj.toString().split("@")[1].toUpperCase();
} while (subtopicMyId.equals("") || existingMyIds.contains(subtopicMyId));
// set myid on this node
subtopicNode.setProperty("myid", subtopicMyId);
subtopicNode.setProperty("parentid", topicMyId);
subtopicNode.save();
// add new myid to list of existsing IDs so that it doesn't get reused
existingMyIds.add(subtopicMyId);
} else {
// if subtopic has myid already
// compare the parentid to the parent myid
String subtopicParentId = subtopicNode.getProperty("parentid").getString();
if (!subtopicParentId.equals(topicMyId)) {
// they don't match
String subtopicNodePath = subtopicNode.getPath();
String topicNodePath = topicNode.getPath();
// find path to topic node that has matching myid to this subtopic's parentid
// loop through parent nodes
NodeIterator reorgTopicsIter = compNode.getNodes();
while (reorgTopicsIter.hasNext()) {
// loop through parent objects to find a matching myid for parentid
Node reorgTopicNode = (Node)reorgTopicsIter.next();
// get the myid property from this node, if it exists, and compare the parentid to it
String reorgTopicMyId = reorgTopicNode.hasProperty("myid") ? reorgTopicNode.getProperty("myid").getString() : "";
if (!reorgTopicMyId.equals("")) {
// parent myid exists and is not blank
if (reorgTopicMyId.equals(subtopicParentId)) {
// parentid does match parent myid
String reorgTopicNodePath = reorgTopicNode.getPath();
// determine how many parent objects there are
int reorgTopicSubtopics = 0;
NodeIterator reorgSubtopicsIter = reorgTopicNode.getNodes();
while (reorgSubtopicsIter.hasNext()) {
Node reorgSubtopicNode = (Node)reorgSubtopicsIter.next();
reorgTopicSubtopics++;
}
// set source to this child object
String source = subtopicNode.getPath();
// set destination to matching parent object with new child object appended
String destination = reorgTopicNodePath + "/subtopic-" + (reorgTopicSubtopics + 1);
// create session for move and perform move
Session session = resourceResolver.adaptTo(Session.class);
session.move(source, destination);
session.save();
} else {
// parentid does not match parent myid.
// nothing we need to do here;
// it just moves on to check next parent myid.
}
} else {
// parent myid does not exist or is blank
}
} else {
// no more parent objects to loop through, so we need to check if a match was found
// if no match was found, then parent was deleted or no longer exists, so we need to remove this child
}
} else {
// parentid does match parent myid
}
}
ist der Fehler in der Konsole:
An error occurred at line: 145 in the jsp file: /apps/covidien/components/content/utilities/faq-node-process/faq-node-process.jsp
Syntax error on token "else", delete this token
142: subtopicNode.save();
143: // add new myid to list of existsing IDs so that it doesn't get reused
144: existingMyIds.add(subtopicMyId);
145: } else {
146: // if subtopic has myid already
147: // compare the parentid to the parent myid
148: String subtopicParentId = subtopicNode.getProperty("parentid").getString();
Einer dieser else Blöcke dauert eine Weile. Ich habe den Eindruck, dass es in Ordnung ist, diese Art von Syntax zu verwenden. Liege ich falsch? – Tyrelius
@TyB Nein, 'else' geht nur nach' if'. – EJP
nein .. du kannst sonst nicht mit – stinepike